Hi, I'm having some troubles when trying to solve a system of ODE.
This is the equation that I'm trying to solve: with initial conditions .
When solving the equation numerically I obtained the next plot in the interval from to .
I tried to do the same with Simulink, but the resulting graph from the scope its the next one:
The Simulink diagram is the next:
Thanks in advance.
Oscar Espinosa

 채택된 답변

Stephan
Stephan 2020년 11월 7일

0 개 추천

I think something went wrong, when you solved numeric:
syms y(t)
eq = diff(y,t,4) + 3 * diff(y,t,2) - sin(t) * diff(y,t,1) + 8 * y == t^2;
[V,S] = odeToVectorField(eq);
fun = matlabFunction(V,'Vars',{'t','Y'});
[tsol, ysol] = ode45(fun,[0 20], [1 2 3 4]);
plot(tsol, ysol(:,1))
result is:
The equation in Simulink:
gives:
Which is the same result. I think you have to switch the x0-Inputs with the signal inputs of your 4 integrators to solve the issue.

댓글 수: 1

Hi, Stephan
That helped to me, thank you. By the way I'll like to show how I tried to solve the ODE like a system of ODE, so:
xconds = [1;2;3;4];
function dxdt = ode_4th_order(t,x)
dxdt(1,1) = x(2,1);
dxdt(2,1) = x(3,1);
dxdt(3,1) = x(4,1);
dxdt(4,1) = -3*x(3,1)+sin(t)*x(2,1)-x(1,1)+t^2;
end
[t,x] = ode45('ode_4th_order',tspan,xconds);
plot(t,x(:,1));
But this give a completely different graph, the one that you see in the original post. Does this approach work? I mean, there is something that I did wrong or something missing?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

제품

릴리스

R2016a

태그

질문:

2020년 11월 7일

댓글:

2020년 11월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by