need help writing the code to these equation using ode45

HERE ARE MY 3 EQUATIONS AND BOUNDARY CONDITIONS BELOW

7 件のコメント

Jan
Jan 2019 年 3 月 7 日
What have you tried so far? What kind of help do you need for which part of the solution?
Daniel Kubiat
Daniel Kubiat 2019 年 3 月 7 日
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
Jan
Jan 2019 年 3 月 7 日
How can we help you? Did you try anything to solve the problem by your own?
Daniel Kubiat
Daniel Kubiat 2019 年 3 月 7 日
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
Jan
Jan 2019 年 3 月 7 日
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.
Daniel Kubiat
Daniel Kubiat 2019 年 3 月 8 日
編集済み: Jan 2019 年 3 月 8 日
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';
Jan
Jan 2019 年 3 月 8 日
Please post a copy of the complete error message, because this helps to identify and solve the error. How do you call ode45?

サインインしてコメントする。

 採用された回答

Jan
Jan 2019 年 3 月 8 日

1 投票

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 件のコメント

darova
darova 2019 年 3 月 8 日
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
Daniel Kubiat
Daniel Kubiat 2019 年 3 月 8 日
thanks alot for this. life savers on this group. i dont even know how i would repay this kind help
darova
darova 2019 年 3 月 9 日
you can accept the answer )
Daniel Kubiat
Daniel Kubiat 2019 年 3 月 14 日
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
darova
darova 2019 年 3 月 14 日
You need to put your function and the main script in different files .m
File with function must have the same name as function
Daniel Kubiat
Daniel Kubiat 2019 年 3 月 14 日
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,:)];
Daniel Kubiat
Daniel Kubiat 2019 年 3 月 14 日
and i understand what you mean by naming the file with same name as fuction
darova
darova 2019 年 3 月 15 日
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?
Jan
Jan 2019 年 3 月 15 日
編集済み: Jan 2019 年 3 月 15 日
@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.

サインインしてコメントする。

その他の回答 (6 件)

Daniel Kubiat
Daniel Kubiat 2019 年 3 月 9 日

0 投票

Unknown.jpg

2 件のコメント

Daniel Kubiat
Daniel Kubiat 2019 年 3 月 9 日
this is the error im getting please help
darova
darova 2019 年 3 月 9 日
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);

サインインしてコメントする。

Daniel Kubiat
Daniel Kubiat 2019 年 3 月 9 日

0 投票

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

1 件のコメント

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

サインインしてコメントする。

Daniel Kubiat
Daniel Kubiat 2019 年 3 月 9 日

0 投票

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

2 件のコメント

Jan
Jan 2019 年 3 月 10 日
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.
Daniel Kubiat
Daniel Kubiat 2019 年 3 月 14 日
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,:)];

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

質問済み:

2019 年 3 月 7 日

編集済み:

Jan
2019 年 3 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by