Summing results of ode45

조회 수: 8 (최근 30일)
gorilla3
gorilla3 2017년 10월 13일
댓글: Jan 2017년 10월 18일
Hello, using ode45 I solved 3 differential equations. I now want to create a function x that adds all the 3 components of the diff equations. Could you help me set it up?
Fx=@(t,xqxc)[ (-xqxc(1)+G_q .*(q-q_b)./q_b)./tau_q ;
(-xqxc(2) +0.3+3.*tanh(Pa_co2./Pa_co2_b -1.1))./tau_co2 ]
[t, xqxc]=ode45(F,[0 100], [0 0 0]);
xq= xqxc(:,1);
xc= xqxc(:,2);
syms xm(t)
[V] = odeToVectorField(diff(xm, 2) == (-tau2*diff(xm) -xm)/tau1^2)
M = matlabFunction(V,'vars', {'t','Y'})
sol = ode45(M,[0 20],[2 0]);
x= sol+ xc -xq;
the error I get is Undefined operator '+' for input arguments of type 'struct'.
Error in CBF_v2 (line 56) x= sol+ xc -xq;
  댓글 수: 8
Torsten
Torsten 2017년 10월 17일
Solve all equations simultaneously (7 as far as I can see).
This will resolve all your problems.
Best wishes
Torsten.
gorilla3
gorilla3 2017년 10월 17일
Oh, I made such a silly mistake! Thank you, Torsten!!

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

답변 (1개)

Jan
Jan 2017년 10월 15일
sol = ode45(...) replies a struct, as the error message tells clearly. Either use:
x = sol.y + xc - xq;
Or use two outputs
[t2, x2] = ode45(...)
You obtain xc from t=0 to 100, but the 2nd integration goes from 0 to 20. Are you sure that you can add them directly? Is this meaningful?
You provide an initial with 3 elements in:
[t, xqxc] = ode45(F,[0 100], [0 0 0]);
But F replies a [2 x 1] vector only.
  댓글 수: 4
gorilla3
gorilla3 2017년 10월 17일
I asked this in multiple ways but I really don't know how to solve the problem. I need a system of two 1st order diff eq and one 2nd order diff eq. I tried numerous approaches, please help me. This is how far I got:
Fx=@(t,xqxc)[ (-xqxc(1)+G_q .*(q-q_b)./q_b)./tau_q ;
(-xqxc(2) +0.3+3.*tanh(Pa_co2./Pa_co2_b -1.1))./tau_co2;
%2nd order diff: xm'' = (-tau2* xm' -xm)/tau1^2
%xm' ??
%xm''
(-tau2.*xqxcxmxm1(4) - xqxcxmxm1(3))./tau1.^2]
[t, xqxc]=ode45(F,[0 100], [0 0 0]);
xq= xqxc(:,1);
xc= xqxc(:,2);
xm= xqxc(:,3);
xm1= xqxc(:,4);
x=xm+ xc -xq;
Jan
Jan 2017년 10월 18일
You can convert the 2nd order system to a 1st order system easily. Then you can integrate both trajectories together. Or you define tspan as a vector, such the output of the integrator is calculated for the same time points. Then you can add the trajectories directly.
But currently you integrate one trajectory from 0 to 100, and the other from 0 to 20. Then it does not look logical to sum the trajectories.
Summary: I still do not understand exactly, what you are asking for.

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

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by