code:
function mainsolve
M=[1 0 0 0;
0 1 0 0;
0 0 0 0;
0 0 0 0];
y0=[1;0;1;0];
tspan=[0,1];
options = odeset('Mass',M,'RelTol',1e-4,...
'AbsTol',[1e-6 1e-6 1e-6,1e-6],...
'Vectorized','on');
[t,y] = ode15s(@ct,tspan,y0,options);
plot(t,y);
function dy=ct(r,y)
dy=[-8*y(1)+8*y(3)+0.2*(1-y(2))*exp(20-20/y(1));
-8*y(2)+8*y(4)+0.2*(1-y(2))*exp(20-20/y(1));
-4*y(1)+5*y(3)-0.92;
-4*y(2)+4*y(4)];
errors message:
Error using -
Matrix dimensions must agree.
Error in odenumjac (line 147)
Fdiff = Fdel - Fvalue(:,ones(1,ny));
Error in daeic12 (line 37)
[DfDy,Joptions.fac,nF] = odenumjac(fun, {t0,y,args{:}}, f, Joptions);
Error in ode15s (line 310)
[y,yp,f0,dfdy,nFE,nPD,Jfac] = daeic12(odeFcn,odeArgs,t,ICtype,Mt,y,yp0,f0,...
Error in mainsolve (line 11)
[t,y] = ode15s(@ct,tspan,y0,options);

댓글 수: 2

KSSV
KSSV 2016년 6월 15일
what is the differential equation you are trying to solve?
Xiao Sidao
Xiao Sidao 2016년 6월 15일
<< |
|>>

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

 채택된 답변

Torsten
Torsten 2016년 6월 15일

0 개 추천

Does this work ?
function mainsolve
M=[1 0 0 0
0 1 0 0
0 0 0 0
0 0 0 0];
y0=[1 0 0.984 0];
tspan=[0 1];
options = odeset('Mass',M,'RelTol',1e-4,...
'AbsTol',[1e-6 1e-6 1e-6,1e-6],...
'Vectorized','on');
[t,y] = ode15s(@ct,tspan,y0,options);
plot(t,y)
function dy=ct(r,y)
dy=[-8*y(1)+8*y(3)+0.2*(1-y(2))*exp(20-20/y(1))
-8*y(2)+8*y(4)+0.2*(1-y(2))*exp(20-20/y(1))
-4*y(1)+5*y(3)-0.92
-4*y(2)+4*y(4)];
Best wishes
Torsten.

댓글 수: 3

Xiao Sidao
Xiao Sidao 2016년 6월 16일
sorry, it did not work and the same errors again.
Torsten
Torsten 2016년 6월 16일
편집: Torsten 2016년 6월 16일
Use
options = odeset('Mass',M,'RelTol',1e-4,...
'AbsTol',[1e-6 1e-6 1e-6 1e-6],...
'Vectorized','off');
since your function ct does not look vectorized to me.
Best wishes
Torsten.
Xiao Sidao
Xiao Sidao 2016년 6월 16일
OK,thank you! You are excllent.It works well.

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기

제품

질문:

2016년 6월 15일

댓글:

2016년 6월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by