The differential equation problem with variable solution by using ode45
1 次查看(过去 30 天)
显示 更早的评论
I have four coupled diffrential equation shown bellow :-
In which a ,b ,c ,d ,e,f are constant and x[t] we will get from the solution of this second order diffrential equation .how to write code for it in matlab.plz help
4 个评论
采纳的回答
darova
2019-10-31
Here is an idea
[t1,x1] = ode45(@F1,ts,x0); % solve second order
[t2,s] = ode45(@(t,s)F2(t,s,t1,x1(:,1)),ts,s0); % solve system
function ds = F2(t,s,t1,x1)
x = interp1(t1,x1,t); % extract x
ds(1,1) = a*x-b ...
ds(2,1) = c*x*s(1) ...
end
3 个评论
darova
2019-10-31
编辑:darova
2019-10-31
Here is how your code should look like
function main
%% your constants
[t1,x1] = ode45(@noscillator,[0 10],[0 1]);
[t2,s1] = ode45(@(t,s) xotss(t,s,t1,x1(:,1)), [0 10], [1 0 0 0]);
plot(t2,s1(:,1))
function xdot=noscillator(t,x)
xdot(1) = x(2);
xdot(2) = -(omega^2)*x(1)-3*(gamma/m)*x(1)^2 - 4*(beta/m)*x(1)^3 + (V/m)*cos(w *t);
xdot=xdot';
end
function dxdt = xotss(t,s,t1,x1)
x = interp1(t1,x1,t);
dxdt(1) = (a*x-b)*s(1) + c*x*s(2);
% ...
dxdt = -1i*dxdt'
end
end
更多回答(6 个)
abhishek singh
2019-10-31
1 个评论
darova
2019-10-31
It means
सदस्यता सूचकांकों को वास्तविक धनात्मक पूर्णांक या तार्किक होना चाहिए।
In your language. Any ideas what the problem it might be?
Walter Roberson
2019-10-31
[t1,x1] = ode45(@noscillator,[0:100],[0 1]);
[t2,s1] = ode45(@(t,s) xotss(t,s,t1,x1(:,1)), [0:100], [1 0 0 0]);
for ti = 0:1:100
rho11(ti+1)=s1(ti+1,1).*s1(ti+1,1)'-s1(ti+1,3).*s1(ti+1,3)';
rho12(ti+1)=s1(ti+1,1).*s1(ti+1,2)'+s1(ti+1,3).*s1(ti+1,4)';
rho21(ti+1)=s1(ti+1,2).*s1(ti+1,1)'+s1(ti+1,4).*s1(ti+1,3)';
rho22(ti+1)=s1(ti+1,2).*s1(ti+1,2)'-s1(ti+1,4).*s1(ti+1,4)';
end
3 个评论
Walter Roberson
2019-11-1
Note that s1(ti+1,1)' means the conjugate complex transpose of s1(ti+1,1) . It is, however, a scalar, so transpose does not make any change. The You are also expecting real-valued results, so the conjugate is probably not makeing any changes. I suspect you are doing the equivalent of squaring the value.
I worry that you might have that that s1(ti+1,1)' is the derivative of s1(ti+1,1) .
abhishek singh
2019-11-1
1 个评论
Rik
2019-11-1
Please do not post your comments as answer. Their order can change, which makes it confusing.
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!