The graph for the ODE45 function does not work

2 visualizzazioni (ultimi 30 giorni)
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 Commento
HWIK
HWIK il 16 Gen 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

Accedi per commentare.

Risposta accettata

HWIK
HWIK il 16 Gen 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 Commento
Mohamed T. Adam
Mohamed T. Adam il 16 Gen 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

Accedi per commentare.

Più risposte (0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by