need help writing the code to these equation using ode45

HERE ARE MY 3 EQUATIONS AND BOUNDARY CONDITIONS BELOW

7 Comments

What have you tried so far? What kind of help do you need for which part of the solution?
transformation of 3rd order non homogeneous ODEs to a first order ODE for ease of simulation. im being told ODE45 is suitable to solve it and i need help solving this problem and get code running
How can we help you? Did you try anything to solve the problem by your own?
i tried using ode 45 to solve but code didnt run. my coding is rough was hoping i could get some help from here please
It is very likely that the forum will help you, when you show your own effort. Post the current version of the code and the produced error message, if there is one.
If you want others to solve your work, maybe hiring a professional programmer is a valid option. Many members of this forum do not like to be treated as cheap programming service.
oh my God. im really sorry that was not my intention. i have never used this forum qnd never understood how it works. really sorry if my actions sent a bad mesaage. ill send the code and its error.
this is my code i generated with the little i know but it says error in command window when i call ode45 i think theres a problem
function ydot = func(t,ydot)
ydot(1) = y(2);
ydot(2) = y(3);
ydot(3) = -(y(1)*y(2)) + (0.5*y(2));
ydot(4) = y(5);
ydot(5) = -0.7*(0.1*y(7)*y(5) + 0.1*y(5)*y(5));
ydot(6) = y(7);
ydot(7) = 1*y(5) - 1*y(1);
ydot = @(t, y)[y(2); y(3); -(y(1)*y(2)) + (0.5*y(2)); y(5); -0.7*(0.1*y(7)*y(5)+0.1*(y(5))^2); y(7); -y(6)-(1)*y(1)];
ydot = ydot';
Please post a copy of the complete error message, because this helps to identify and solve the error. How do you call ode45?

Sign in to comment.

 Accepted Answer

Remove the line "ydot = @(t, y)[y(2); y(3); ...", because it is not useful here. The function is called with teh inputs t,y, not ydot. A cleaner version:
function ydot = func(t, y)
ydot = zeros(7, 1); % Pre-allocate
ydot(1) = y(2);
ydot(2) = y(3);
ydot(3) = -y(1) * y(2) + 0.5 * y(2);
ydot(4) = y(5);
ydot(5) = -0.7 * (0.1 * y(7) * y(5) + 0.1 * y(5) * y(5));
ydot(6) = y(7);
ydot(7) = y(5) - y(1);
end

9 Comments

Why dont you definite constants? Are you sure about those coefficients?
function ydot = func(t, y)
% M = ... ?
% Nt = ...?
% Nb = ... ?
% ... ?
ydot = zeros(7, 1); % Pre-allocate
ydot(1) = y(2); % f'
ydot(2) = y(3); % f''
ydot(3) = -y(1) * y(3) + 0.5 * y(2); % f''' = -y(1)*y(3) + 0.5*y(2)
ydot(4) = y(5); % theta'
ydot(5) = -0.7 * (0.1 * y(7) * y(5) + 0.1 * y(5) * y(5)); % theta''
ydot(6) = y(7); % psi'
ydot(7) = - ydot(5) - y(1); % psi''
end
thanks alot for this. life savers on this group. i dont even know how i would repay this kind help
you can accept the answer )
please i need alot of help with the same issue using ode45, the following are my issues and nightmares
  1. i dont know how to put my 6 boundary conditions in this code
  2. im using ode45 and honestly dont have a hang of it
  3. i dont know how ill plot and create graphs.im really rusty and require urgent help as this is a project im being asked to work on
function ydot = func(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.
Msq = 0.5
Nt = 0.1
Nb = 0.1
pr = 0.2
le = 1.0
Ntb = Nt/Nb;
ydot = zeros(7, 1); % Pre-allocate
ydot(1) = y(2); % f '
ydot(2) = y(3); % f ''
ydot(3) = -y(1) * y(3) + 0.5 * y(2); % f''' = -y(1)*y(3) + 0.5*y(2 )
ydot(4) = y(5); % theta '
ydot(5) = -0.7 * (0.1 * y(7) * y(5) + 0.1 * y(5) * y(5)); % theta ''
ydot(6) = y(7); % psi '
ydot(7) = - ydot(5) - y(1); % psi ''
dy = @(t, y)[y(2,:); y(3,:); -(y(1,:)*y(3,:)) + (Msq*y(2,:)); y(6,:); -Pr*(Nb*y(7,:)*y(5,:)+Nt*(y(5,:))^2); y(8,:); -Ntb*y(6,:)-(Le/Nb)*y(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);
end
You need to put your function and the main script in different files .m
File with function must have the same name as function
okay noted so does my boundary condition stay in mfile with function ?
also is it safe to say this is my function?
function ydot = func(t, y )
Msq = 0.5
Nt = 0.1
Nb = 0.1
pr = 0.2
le = 1
Ntb = Nt/Nb;
ydot = zeros(7, 1); % Pre-allocate
ydot(1) = y(2); % f '
ydot(2) = y(3); % f ''
ydot(3) = -y(1) * y(3) + 0.5 * y(2); % f''' = -y(1)*y(3) + 0.5*y(2 )
ydot(4) = y(5); % theta '
ydot(5) = -0.7 * (0.1 * y(7) * y(5) + 0.1 * y(5) * y(5)); % theta ''
ydot(6) = y(7); % psi '
ydot(7) = - ydot(5) - y(1); % psi ''
dy = @(t, y)[y(2,:); y(3,:); -(y(1,:)*y(3,:)) + (Msq*y(2,:)); y(6,:); -Pr*(Nb*y(7,:)*y(5,:)+Nt*(y(5,:))^2); y(8,:); -Ntb*y(6,:)-(Le/Nb)*y(1,:)];
and i understand what you mean by naming the file with same name as fuction
Your initial conditions must be in main file.
What it this?
dy = @(t, y)[y(2,:); y(3,:); -(y(1,:)*y(3,:)) + (Msq*y(2,:)); y(6,:); -Pr*(Nb*y(7,:)*y(5,:)+Nt*(y(5,:))^2); y(8,:); -Ntb*y(6,:)-(Le/Nb)*y(1,:)];
ydot looks like dy. Dont you think?
@Daniel: Please format the code in the forum to increase its readability. Look at the icons on top of the field for entering the messages.
It is confusing, that your function to be integrated computes "ydot" and "dy", while the latter is not replied as output. In my suggested code, I did not define constants, because the computation of the replied ydot does not contain any constants.
Decide if you want to use dy or ydot. Then:
function main
y0 = [0, ... % f
0, ... % f'
0, ... % f''
0, ... % theta
0, ... % theta'
0, ... % psi
0]; % psi'
[t, y] = ode45(@kubieode, [0,20], y0);
plot(t, y);
end
function ydot = func(t, y)
Msq = 0.5;
Nt = 0.1;
Nb = 0.1;
Pr = 0.2; % Was "pr", but later called "Pr"
le = 1.0;
Ntb = Nt/Nb;
% EITHER:
ydot = zeros(7, 1); % Pre-allocate
ydot(1) = y(2); % f '
ydot(2) = y(3); % f ''
ydot(3) = -y(1) * y(3) + 0.5 * y(2); % f''' = -y(1)*y(3) + 0.5*y(2 )
ydot(4) = y(5); % theta '
ydot(5) = -0.7 * (0.1 * y(7) * y(5) + 0.1 * y(5) * y(5)); % theta ''
ydot(6) = y(7); % psi '
ydot(7) = - ydot(5) - y(1); % psi ''
% OR:
ydot = [ ...
y(2,:); ...
y(3,:); -(y(1,:)*y(3,:)) + (Msq*y(2,:)); ...
y(6,:); ...
-Pr*(Nb*y(7,:)*y(5,:) + Nt*(y(5,:))^2); ...
y(8,:); ...
-Ntb*y(6,:)-(Le/Nb)*y(1,:)];
end
The two definitions of ydot differ and I cannot decide, which one is wanted.

Sign in to comment.

More Answers (6)

Unknown.jpg

2 Comments

this is the error im getting please help
you have to provide 7 initial conditions (you provided only 2)
y0(1) = ... % f
y0(2) = ... % f'
y0(3) = ... % f''
y0(4) = ... % theta
y0(5) = ... % theta'
y0(6) = ... % psi
y0(7) = ... % psi'
[t, y] = ode45(@kobieode, tspan, y0);

Sign in to comment.

i used 0 as my 7 boundary condition. really dont know why code isnt running. *crying

1 Comment

First of all, look at your equations. What happens if all initial conditions are zeros?
[t y] = ode45(@kobieode,[0,20],y0);

Sign in to comment.

this was the result of i got when i ran it now. no error

2 Comments

Is ths problem solved now? If not, please post a copy of the code and of the error message (if there is one) as text, not as photo. Use the section for answers only for answers, not for comments, to reduce confusions.
Unknown-3.jpeg
also i dont know if i got my tansformation right from my equation on the picture above. please anyone kind enough to take a look
ydot = zeros(7, 1); % Pre-allocate
ydot(1) = y(2); % f '
ydot(2) = y(3); % f ''
ydot(3) = -y(1) * y(3) + 0.5 * y(2); % f''' = -y(1)*y(3) + 0.5*y(2 )
ydot(4) = y(5); % theta '
ydot(5) = -0.7 * (0.1 * y(7) * y(5) + 0.1 * y(5) * y(5)); % theta ''
ydot(6) = y(7); % psi '
ydot(7) = - ydot(5) - y(1); % psi ''
dy = @(t, y)[y(2,:); y(3,:); -(y(1,:)*y(3,:)) + (Msq*y(2,:)); y(6,:); -Pr*(Nb*y(7,:)*y(5,:)+Nt*(y(5,:))^2); y(8,:); -Ntb*y(6,:)-(Le/Nb)*y(1,:)];

Sign in to comment.

Categories

Find more on Mathematics in Help Center and File Exchange

Asked:

on 7 Mar 2019

Edited:

Jan
on 15 Mar 2019

Community Treasure Hunt

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

Start Hunting!