Message Boards Message Boards

GROUPS:

DensityPlot3D working too slowly - How to make it faster?

Posted 2 months ago
530 Views
|
3 Replies
|
2 Total Likes
|

I think it because it plots a function that find fit-parameter to not-small data. the only thing that help me get the plot in a reasonable time is to set PlotPoints->10, but when I go to PlotPoints->50 for more precise plot, it runs for hours. Is there other way to quicken the program?

This is my code:

t1Fitting[x_?NumericQ, y_?NumericQ, z_?NumericQ] := Module[{sol, data, fit, P1, P2, t, a},
  sol = DSolve[{P1'[t] == -(2 y + x) P1[t] + (x - y) P2[t] + y
                P2'[t] == -(2 z + x) P2[t] + (x - z) P1[t] + z, 
                  P1[0] == 1, P2[0] == 0}, {P1, P2}, t];
      data = Flatten[
        Transpose[Table[N[P1[t] - P2[t] /. sol, 15], {t, 0, 25000, 10}]]];
      fit = FindFit[data, Exp[-a t],a, t, WorkingPrecision -> 10];
      a /. fit]

    t1Plot = DensityPlot3D[t1Fitting[x,y,z],{x, 10^-6, 10^-4}, {y, 10^-6, 10^-4}, {z, 10^-6, 10^-4}, PlotPoints -> 50]
3 Replies
Posted 2 months ago

Would it be feasible for you to test each of these (by restarting Mathematica each time and then doing a trivial calculation to start up the kernel and then using AbsoluteTiming) to see how much, if any, time each of these might save versus how much your graph is degraded?

Try substituting {t, 0, 25000, 100} or some other larger number for {t, 0, 25000, 10}

Try removing N[..., 15] to use perhaps faster machine precision calculations

Try removing WorkingPrecision->10 for the same reason

Try changing PlotPoints->10 to PlotPoints->20

The idea is to find which of those or which combination of those might give you enough increase in speed and still have satisfactory graphics resolution.

Are there missing _ between x? and between y? in your code or not? Those are different from your z_? Is there a comma missing in your code, perhaps because you had a newline between your two equations and when that was pasted that was lost?

Sivan,

  1. I think that you might be missing a comma. Are your equations:

    {P1'[t] == -(2 y + x) P1[t] + (x - y) P2[t] + y P2'[t] == -(2 z + x) P2[t] + (x - z) P1[t] + z}
    

or

{P1'[t] == -(2 y + x) P1[t] + (x - y) P2[t] + y, P2'[t] == -(2 z + x) P2[t] + (x - z) P1[t] + z}

I believe you probably meant the later but you coded the former (both are valid although the first, the one you are using, is an unusual way to express the system of equations).

  1. you are doing something computationally evil. You are recomputing the solution to a differential equation over and over for different data. The differential equation should be solved once and reused.

For example:

nsol = DSolveValue[{P1'[t] == -(2 y + x) P1[t] + (x - y) P2[t] + y, 
     P2'[t] == -(2 z + x) P2[t] + (x - z) P1[t] + z, P1[0] == 1, 
     P2[0] == 0}, P1[t] - P2[t], t] // FullSimplify;

This will give you the response you use (P1-P2) as a function of x,y,and z.

  1. why are you fitting an exponential to your solution? The solution to a second order linear differential equation is the summation of two exponential terms. These two terms will never change and you can get them analytically as a function of x,y,and z. What is the meaning of your blended exponential answer? (Of course trying to fit more than one exponential is numerically unstable so I would not try that). If you explain your goal, I can make a better suggestion.

Regards,

Neil

Posted 1 month ago

The reason Iam fittinf exponential to a known function is because this is how people are measuring the system that I am looking at, and to know the values range of the parameters I use to describe this system (x, y, z), I must fit it this way.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract