필터 지우기
필터 지우기

The graph for the ODE45 function does not work

조회 수: 2 (최근 30일)
Mohamed T. Adam
Mohamed T. Adam 2022년 1월 16일
댓글: Mohamed T. Adam 2022년 1월 16일
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