need help writing the code to these equation using ode45
2 ビュー (過去 30 日間)
古いコメントを表示
HERE ARE MY 3 EQUATIONS AND BOUNDARY CONDITIONS BELOW
7 件のコメント
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
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
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
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
2019 年 3 月 9 日
2 件のコメント
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
2019 年 3 月 9 日
1 件のコメント
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
2019 年 3 月 9 日
2 件のコメント
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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!