필터 지우기
필터 지우기

I have a set of second order differential nonlinear equation and I want to solve them together with ode45, how could I write codes for them?or better to say I want to define state transition function for such equations.

조회 수: 2 (최근 30일)
first three equations all variable and constants are not in vector or matrix form but 4th equation is a 3by1 vector like this:
x''=y'+y+x-(x)/(x^2+y^2+z^2)^1.5+1
y''=x'-x+y-y/(x^2+y^2+z^2)^1.5
z''=-z/(x^2+y^2+z^2)^1.5
m''=[x'' y'' z'']'+[1 2 3]
and I want to write function for this system like this function that i have found in one of matlab example:
function dxdt = vdpStateFcnContinuous(x)
%vdpStateFcnContinuous Evaluate the van der Pol ODEs for mu = 1
dxdt = [x(2); (1-x(1)^2)*x(2)-x(1)];
end
  댓글 수: 2
roya afshar
roya afshar 2018년 12월 15일
편집: madhan ravi 2018년 12월 15일
I dont have Latex but I write like this:
syms x(t) y(t) z(t) m(t)
eqn1 = diff(x,t,2) == diff(y,t)+y+x-((x)/(x^2+y^2+z^2)^1.5)+1;
eqn2 = diff(y,t,2) == diff(x,t)-x+y-((y)/(x^2+y^2+z^2)^1.5);
eqn3 = diff(z,t,2) ==-(z)/(x^2+y^2+z^2)^1.5;
eqn4 = diff(m,t,2) == [eqn1 eqn2 eqn3]'+[1;2;3];
latex(eqn1)
latex(eqn2)
latex(eqn3)
latex(eqn4)
is it ok?

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

채택된 답변

madhan ravi
madhan ravi 2018년 12월 17일
I believe :
[t,x]=ode45(@eqns,[0 10],[1;0;0;0;0;0;0;0;0;0;0;0]); % function call
plot(t,x(:,1)) % to plot the solution
function dxdt = eqns(t,x) % function definition
dxdt = [x(2);
x(4)+x(5)+x(1)-(x(1)/((x(1)^2+x(3)^2+x(5)^2)^1.5))+1;
x(4);
x(2)-x(1)+x(3)-(x(3)/((x(1)^2+x(3)^2+x(5)^2)^1.5));
x(6);
-x(5)/((x(1)^2+x(3)^2+x(5)^2)^1.5);
x(2:2:6);
[x(4)+x(5)+x(1)-(x(1)/((x(1)^2+x(3)^2+x(5)^2)^1.5))+1;x(2)-x(1)+x(3)-(x(3)/((x(1)^2+x(3)^2+x(5)^2)^1.5));-x(5)/((x(1)^2+x(3)^2+x(5)^2)^1.5)]+[1;2;3]];
end

추가 답변 (1개)

roya afshar
roya afshar 2018년 12월 17일
function dxdt = eqns(x)
one = 7:9;
two = 10:12;
dxdt = [x(2);
x(4)+x(5)+x(1)-(x(1)/((x(1)^2+x(3)^2+x(5)^2)^1.5))+1;
x(4);
x(2)-x(1)+x(3)-(x(3)/((x(1)^2+x(3)^2+x(5)^2)^1.5));
x(6);
-x(5)/((x(1)^2+x(3)^2+x(5)^2)^1.5);
x(tw0);
[x(4)+x(5)+x(1)-(x(1)/((x(1)^2+x(3)^2+x(5)^2)^1.5))+1;x(2)-x(1)+x(3)-(x(3)/((x(1)^2+x(3)^2+x(5)^2)^1.5));-x(5)/((x(1)^2+x(3)^2+x(5)^2)^1.5)]+[1;2;3]];
end
Could it be true answer? Could anyone make me sure about the answer please?

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by