Question

I am new to matlab, and am trying to implement RungaKutta Method to solve Third Order simultaneous differential equations using ODE45. The below code has been written taking assistance through online available articles and papers. I am getting the following errors. Can someone please take a look?

The set of equations I am trying to solve are: Set of equations

File: freeconvect.m

function Y=freeconvect(eta,X,Pr,Le)
% X=(F0; F1; F2; Theta0; Theta1; Phi0; Phi1)
Nb=0;
Nt=0;
dF0deta=X(2);
df1deta=X(3);
dF2deta=((X(2))^2)-(X(1)*X(3));%-3*X(1)*X(3)+2*(X(2))^2-X(4);
dTheta0deta=X(5);
%dTheta1deta=((-1)*Pr)*((X(1)*X(5))+(Nb*X(7)*X(5))+(Nt*(X(7))^2));%-3*Pr*X(1)*X(5);
dPhi0deta=X(7);
dPhi1deta=(-1)*((Le*X(1)*X(5))+((Nt/Nb)*((-1)*Pr)*((X(1)*X(5))+(Nb*X(7)*X(5))+(Nt*        (X(7))^2))));%-3*Pr*X(1)*X(5);
Y=[dF0deta; dF1deta; dF2deta; dTheta0deta; dPhi0deta; dPhi1deta];

File: Untitled3.m

% ODE45 Solver for freeconvect.m
Pr=10;
Le=10;
etaspan=[0 10] ;
Xinit=[0;1;1;1;1;1;1];
[Eta,X]=ode45(@freeconvect,etaspan,Xinit,Pr,Le);
plot(Eta,X);

ERROR-------------------------------------------------------

>> Untitled3
Attempted to access X(7); index out of bounds because numel(X)=6.

Error in freeconvect (line 10)
dPhi0deta=X(7);

Error in odearguments (line 88)
f0 = feval(ode,t0,y0,args{:});   % ODE15I sets args{1} to yp0.

Error in ode45 (line 114)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...

Error in Untitled3 (line 10)
[Eta,X]=ode45(@freeconvect,etaspan,Xinit,Pr,Le);
Was it helpful?

Solution

I don't think that ode45 is the right tool for this problem. ode45 is designed to solve initial value problems. Based your "boundary conditions" you have a boundary value problem. As far as Matlab goes, start here.

The error you're getting is due to this line in your freeconvect function:

dPhi0deta=X(7);

According to the comments at the top X(7) is Phi1, but you've only specified Xinit with six values.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top