MATLAB Answers

0

ode45 code not running and need help imputing my boundary conditions

Asked by Daniel Kubiat on 15 Mar 2019
Latest activity Commented on by Torsten
on 15 Mar 2019
here is my matlab function code and the error i keep getting when running it also i would like to know how and where i can put my boundary condition in this code
function ydot = kubieode(t, y )
%define variables making it more legible
% Numerical Integration of Differential Equation
% Numerical Integration of a 3rd order ODE using ODE45 solver embedded in
% MATLAB.
%Pr is the Prantl number of the concerned fluid respectively.
%Le: Lewis number
%Nb: Brownian motion parameter
%Nt: Thermophoresis parameter
Msq = 0.5;
Nt = 0.1;
Nb = 0.1;
Pr = 0.2;
Le = 1.0;
ydot = zeros(7, 1); % Pre-allocate
ydot(1) = y(2); % f '
ydot(2) = y(3); % f ''
ydot(3) = -y(1) * y(3) + Msq * y(2); % f''' = -y(1)*y(3) + 0.5*y(2 )
ydot(4) = y(5); % theta '
ydot(5) = -Pr * (Nb * y(7) * y(5) + Nt * y(5) * y(5)); % theta ''
ydot(6) = y(7); % psi '
ydot(7) = - (Nt/Nb) * ydot(5) - (Le/Nb) * y(1); % psi ''
end
HERER IS THE COMMAND WINDOW AND RESULT/ERROR
y0(1) = 0 % f
y0(2) = 0 % f'
y0(3) = 0 % f''
y0(4) = 0 % theta
y0(5) = 0 % theta'
y0(6) = 0 % psi
y0(7) = 0 % psi'
[t y] = ode45(@kubieode,[0,20],y0);
[t,y]; %to print
plot(t,y(:,1));
y0 =
0 0 0 0 0 0 0
y0 =
0 0 0 0 0 0 0
y0 =
0 0 0 0 0 0 0
y0 =
0 0 0 0 0 0 0
y0 =
0 0 0 0 0 0 0
y0 =
0 0 0 0 0 0 0
y0 =
0 0 0 0 0 0 0
Msq =
0.5000
Nt =
0.1000
Nb =
0.1000
pr =
0.2000
le =
1
??? Undefined function or variable 'y0'.
Error in ==> kubieode at 30
[t,y] = ode45('kubieode',[0,20] ,y0);
Error in ==> odearguments at 110
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...

  3 Comments

If you start with y0=0, y will be 0 for all times.
so what do i start with? and how do i impute my boundary conditions to this code
See the code below on how to input your boundary conditions.
It's up to you to know which boundary conditions to take.

Sign in to comment.

1 Answer

Answer by Torsten
on 15 Mar 2019
 Accepted Answer

function main
y0=zeros(7,1);
y0(1) = 0; % f
y0(2) = 0; % f'
y0(3) = 0; % f''
y0(4) = 0; % theta
y0(5) = 0; % theta'
y0(6) = 0; % psi
y0(7) = 0; % psi'
[t y] = ode45(@kubieode,[0,20],y0);
plot(t,y(:,1));
end
function ydot = kubieode(t, y )
%define variables making it more legible
% Numerical Integration of Differential Equation
% Numerical Integration of a 3rd order ODE using ODE45 solver embedded in
% MATLAB.
%Pr is the Prantl number of the concerned fluid respectively.
%Le: Lewis number
%Nb: Brownian motion parameter
%Nt: Thermophoresis parameter
Msq = 0.5;
Nt = 0.1;
Nb = 0.1;
Pr = 0.2;
Le = 1.0;
ydot = zeros(7, 1); % Pre-allocate
ydot(1) = y(2); % f '
ydot(2) = y(3); % f ''
ydot(3) = -y(1) * y(3) + Msq * y(2); % f''' = -y(1)*y(3) + 0.5*y(2 )
ydot(4) = y(5); % theta '
ydot(5) = -Pr * (Nb * y(7) * y(5) + Nt * y(5) * y(5)); % theta ''
ydot(6) = y(7); % psi '
ydot(7) = - (Nt/Nb) * ydot(5) - (Le/Nb) * y(1); % psi ''
end
Put the code from above in a file, name it main.m, load it into MATLAB and run it.

  0 Comments

Sign in to comment.