dsolve error (simultaneous differential equations)

clear all
close
clc
m = 10;
k = 1000;
u0 = 0.01;
syms y1 y2
f=dsolve('m*D2y1+2*k*y1-k*y2==0,m*D2y2-k*y1+2k*y2==0','y1(0)==0,Dy1(0)==0,Dy2(0)==0,y2(0)==0.01');
figure
ezplot(f,[0 100]);
I want to solve simultaneous differential equation but i have a problem solving it.
Can someone help me find whats causing error?

 Respuesta aceptada

Here is the answer:
clear all
close
clc
m = 10;
k = 1000;
u0 = 0.01;
syms y1(t) y2(t)
Dy1=diff(y1);
Dy2=diff(y2);
D2y1=diff(y1, 2);
D2y2=diff(y2, 2);
Eqn1=m*D2y1+2*k*y1-k*y2;
Eqn2=m*D2y2-k*y1+2*k*y2;
ICs=[y1(0)==0,Dy1(0)==0,Dy2(0)==0,y2(0)==0.01];
f=dsolve(Eqn1,Eqn2, ICs);
figure
ezplot(f.y1,[0 100]), hold on
ezplot(f.y2, [0, 100]), legend('y_1(t)', 'y_2(t)', 'location', 'best')

3 comentarios

Thanks for the Answer.
Can you tell me when i should define differential equation as
Dy1=diff(y1);
Dy2=diff(y2);
D2y1=diff(y1, 2);
D2y2=diff(y2, 2);
as you mentioned?
Because sometimes it works eventhough i don't define like that.
There two different ways of expressing ODE expressions. This is one of them and is the logically structured one. The other one is direct that you define your variable without specifying to differentuiate it w.r.t what variable that may create a problem in cases when there is an obscurity with the existing variables in your MATLAB workspace.
Good luck
Seungwon Lee
Seungwon Lee el 18 de Mayo de 2020
Thanks

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Symbolic Math Toolbox en Centro de ayuda y File Exchange.

Preguntada:

el 18 de Mayo de 2020

Comentada:

el 18 de Mayo de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by