how to solve non linear differential equations

dx(t)/dt=y(t)
dy(t)/dt=-(1/r+g+a+b|x(t)|)y(t)/c-x(t)/(lc)
t=-0.05:0.01:0.05
r = 1430;
a = -0.0683;
b = 0.0676;
c = 36*10^-9;
g = -0.0676;
l=27
i want to plot phase portrait of (x(t),y(t)) and plots for (t,x(t)),(t,y(t))

回答 (1 件)

Bjorn Gustavsson
Bjorn Gustavsson 2021 年 3 月 3 日
編集済み: Bjorn Gustavsson 2021 年 3 月 4 日

0 投票

Have a look at the help and documentation of ode45 and the numerous ode-examples.
In brief to solve this ODE-system write a matlab-function for the derivatives:
function dxdtdydt = your_ode(t,xy,pars)
r = pars(1);
a = pars(2);
b = pars(3);
c = pars(4);
g = pars(5);
l = pars(6);
y = xy(2);
x = xy(1);
dxdt = xy(2);
dydt = -(1/r+g+a+b*abs(x)*y/c-x/(l*c));
dxdtdydt = [dxdt;
dydt];
That ode you then integrate from some initial state over some time-period of interest
r = 1430;
a = -0.0683;
b = 0.0676;
c = 36*10^-9;
g = -0.0676;
l=27;
pars = [r,a,b,c,g,l];
t = -0.05:0.01:0.05;
x0y0 = [0,1]; % I wouldn't know.
[t,xy] = ode45(@(t,xy) your_ode(t,xy,pars),t,x0y0);
HTH

13 件のコメント

nune pratyusha
nune pratyusha 2021 年 3 月 4 日
it showing error like
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched
delimiters.
please refer any supplimentary materials for solving non linear differential equation in matlab
Bjorn Gustavsson
Bjorn Gustavsson 2021 年 3 月 4 日
OK, now edited/corrected the code.
nune pratyusha
nune pratyusha 2021 年 3 月 4 日
edited code also showing error
Bjorn Gustavsson
Bjorn Gustavsson 2021 年 3 月 4 日
Now edited and tested.
nune pratyusha
nune pratyusha 2021 年 3 月 5 日
It's not working
Walter Roberson
Walter Roberson 2021 年 3 月 5 日
Nope, it is working.
r = 1430;
a = -0.0683;
b = 0.0676;
c = 36*10^-9;
g = -0.0676;
l=27;
pars = [r,a,b,c,g,l];
t = -0.05:0.01:0.05;
x0y0 = [0,1]; % I wouldn't know.
[t,xy] = ode45(@(t,xy) your_ode(t,xy,pars),t,x0y0);
plot(t,xy)
function dxdtdydt = your_ode(t,xy,pars)
r = pars(1);
a = pars(2);
b = pars(3);
c = pars(4);
g = pars(5);
l = pars(6);
y = xy(2);
x = xy(1);
dxdt = xy(2);
dydt = -(1/r+g+a+b*abs(x)*y/c-x/(l*c));
dxdtdydt = [dxdt;
dydt];
end
nune pratyusha
nune pratyusha 2021 年 3 月 5 日
but in my system it showing error
nune pratyusha
nune pratyusha 2021 年 3 月 5 日
error
Bjorn Gustavsson
Bjorn Gustavsson 2021 年 3 月 5 日
Have you included all the corrections to your_ode.m?
nune pratyusha
nune pratyusha 2021 年 3 月 5 日
yes
nune pratyusha
nune pratyusha 2021 年 3 月 5 日
now its working thank you sir, but i want output as sin wave
nune pratyusha
nune pratyusha 2021 年 3 月 5 日
dx(t)/dt=y(t)
dy(t)/dt=-(1/r+g+a+b|x(t)|)y(t)/c-x(t)/(lc)
t=-0.05:0.01:0.05
r = 1430;
a = -0.0683;
b = 0.0676;
c = 36*10^-9;
g = -0.0676;
l=27
i want to plot(t,x(t)) and plot(t,y(t))
Bjorn Gustavsson
Bjorn Gustavsson 2021 年 3 月 5 日
Well the solution does not look like a sine-wave. That is because I have yet another typo in the ODE, you will surely find it if you look close and read the code, and think about what you need to obtain an oscillating solution.

サインインしてコメントする。

カテゴリ

製品

リリース

R2020b

質問済み:

2021 年 3 月 3 日

コメント済み:

2021 年 3 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by