Clear Filters
Clear Filters

The graph for the ODE45 function does not work

3 views (last 30 days)
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 Comment
HWIK
HWIK on 16 Jan 2022
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

Sign in to comment.

Accepted Answer

HWIK
HWIK on 16 Jan 2022
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 Comment
Mohamed T. Adam
Mohamed T. Adam on 16 Jan 2022
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

Sign in to comment.

More Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!