# DensityPlot3D working too slowly - How to make it faster?

Posted 9 months ago
1273 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
Sort By:
Posted 9 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 calculationsTry removing WorkingPrecision->10 for the same reasonTry changing PlotPoints->10 to PlotPoints->20The 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, 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). 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. 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