need help writing the code to these equation using ode45

2 ビュー (過去 30 日間)
Daniel Kubiat
Daniel Kubiat 2019 年 3 月 7 日
編集済み: Jan 2019 年 3 月 15 日
HERE ARE MY 3 EQUATIONS AND BOUNDARY CONDITIONS BELOW
  7 件のコメント
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 日
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 月 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 日
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 日
work.jpg

Daniel Kubiat
Daniel Kubiat 2019 年 3 月 9 日
worrrk.jpg

Daniel Kubiat
Daniel Kubiat 2019 年 3 月 9 日
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 日
okka.jpg

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

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

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by