Info

この質問は閉じられています。 編集または回答するには再度開いてください。

What did I do wrong here?

1 回表示 (過去 30 日間)
Zifeng Qiu
Zifeng Qiu 2020 年 7 月 6 日
閉鎖済み: madhan ravi 2020 年 7 月 6 日
I am trying to calculate the amount of fish I can catch in a year based on this model. What did I do wrong? The answer that I got is super huge.
u0 = 5000;
lambda = 0.03;
pm = 9000;
f = @(t,k) lambda*500*(1-500/pm)-k;
[t,k] = RK4(f,u0,100,10)
Kf = k(end)
  2 件のコメント
Image Analyst
Image Analyst 2020 年 7 月 6 日
What I get is
Unrecognized function or variable 'RK4'.
Where did you define that?
Zifeng Qiu
Zifeng Qiu 2020 年 7 月 6 日
Sorry, that was a function that I wrote, here are the code:
function [tv, uv] = RK4(f, u0, T, n)
dt = T/n; % Differential of time.
tv = transpose(0:dt:T); % Evaluation times.
uv = zeros(n+1, 1); % Solution.
uv(1) = u0; % Initial value
for i=1:length(tv)-1
k1 = f(tv(i), uv(i))
k2 = f(tv(i) + (dt/2), uv(i) + dt*k1/2)
k3 = f(tv(i) + (dt/2), uv(i) + dt*k2/2)
k4 = f(tv(i) + dt, uv(i) + dt*k3)
uv(i+1) = uv(i) + dt/6*[k1+2*k2+2*k3+k4]
end
end

回答 (1 件)

Alan Stevens
Alan Stevens 2020 年 7 月 6 日

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by