The graph for the ODE45 function does not work

1 次查看(过去 30 天)
The ODE 45 fuction for the second order derivative does not work, because the plot keeps ocilating and i have done a second method and it does not ocilates. How can i fix it?
edit:
The equation i am trying to solve is :
second derivative of delta_h + (Kc/A) * first derivative of delta_h + (Kc/(A*t1)) * delta_h = 0 %with Kc, A and t1 being constants
with initial conditions:
first derivative of delta_h(0) = 2 , delta_h(0) =0
i have added the other code for comparison. In this code the same fuction reaches zero very quickly and without ocilations. I dont know why they are not similar.
  1 个评论
HWIK
HWIK 2022-1-16
Your question is a bit abstract, mind providing the problem you are trying to solve?
Because all you have said is that your code doesn't work, because it oscillates, and it is not supposed to. Not a great starting point for others to help

请先登录,再进行评论。

采纳的回答

HWIK
HWIK 2022-1-16
I think the script where you use ode45 is correct, because I don't see any errors there, and using a different method I get the same reult:
Kc = 1;
A = 2;
t1 = 0.1;
syms h(t)
dh = diff(h);
ode = diff(h,t,2) + Kc/A*dh + Kc/A/t1*h == 0;
cond1 = h(0) == 0;
cond2 = dh(0) == 2;
conds = [cond1, cond2];
hSol(t) = dsolve(ode,conds);
fplot(hSol)
Perhaps the mistake is in the coursework_2.m script, but I am not sure what method you are using there to solve the ODE, so can't really help with that.
  1 个评论
Mohamed T. Adam
Mohamed T. Adam 2022-1-16
You are right, the mistake was in coursework_2 and i redid the whole code using euler's method and it worked, thank you so much for your help

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by