Single ODE solved with ODE45

3 visualizaciones (últimos 30 días)
Michelle Zhou
Michelle Zhou el 14 de Oct. de 2017
Editada: David Goodmanson el 19 de Oct. de 2017
wspan = 0:0.01:10000;
x0 = 0;
[w,x] = ode45(@(w,x) (0.012528*(1-(9.8*10^(-5)*w))*(1.5-x)*(1-x))/(45*(1+16.68...
*(1-(9.8*10^(-5)*w))^(0.5)*x+12.456*(1-(9.8*10^(-5)*w))^(0.5)*(1-x))),wspan, x0);
plot(w,x,'-o');
I wrote the simple code above with the hope to replicate a graph that I obtained from excel. However, the range of x on the vertical axis in the MATLAB plot are way smaller than what I've expected. Could someone please explain to me how to fix it such that it matches my excel plot. (the excel plot is proven to be correct) Thanks, much appreciated. Attached (Excel Plot & MATLAB Plot)
  3 comentarios
Jan
Jan el 14 de Oct. de 2017
Note: 9.8*10^(-5) is a multiplication and an expensive power operation in every call of the function, while 9.8e-5 is a cheap constant. SQRT(x) is much faster than x^0.5. Runtime is not your problem here, but it is worth to keep this in mind.
Star Strider's idea is obviously right: If the output by Excel is proven to be correct, and the Matlab code does not produce the same result, the Matlab code contains a different formula. We cannot fix it without seeing the correct formula.
Michelle Zhou
Michelle Zhou el 16 de Oct. de 2017
Thanks for the comments, they are more than helpful. I have fixed the problems with the long computation time. The attached is the original ODE I used to do the excel plots, please let me know if anything can be done to produce the same graph as in excel. Once again, thank you very much.

Iniciar sesión para comentar.

Respuestas (1)

David Goodmanson
David Goodmanson el 16 de Oct. de 2017
Editada: David Goodmanson el 19 de Oct. de 2017
Hi Michelle,
Looks like your constant of .012528 is off by a factor of 10, should be .12528. Once that change is made, there is good agreement with the excel plot.

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by