Need help inputting my equation into MATLAB
1 回表示 (過去 30 日間)
古いコメントを表示
(R*(sin((pi*t)/12))^4 + R0)*(Q) - (Q+P)*((M(t))/((V-Q)*t))
The above equation is what I want to input, like this....
%% seawater.m
% Setup equation parameters
V = 10000; Q = 1000; P = 200; R = 10; R0 = 25; M0 = 0;
% Choose a time step h for Euler's method and the inteval [0,tf]
h = 0.01; tf = 120;
t = 0:h:tf;
M = zeros(1,length(t));
M(1) = M0;
% Enter the right side of the differential equation for M
% in terms of P, Q, R, R0 and V.
f = @(t,M) (R*(sin((pi*t)/12))^4 + R0)*(Q) - (Q+P)*((M(t))/((V-Q)*t));
% Implement Euler's method
for n=1:length(t)-1
M(n+1) = M(n) + f(t(n),M(n))*h;
end
% Plot the solution
plot(t,M/V), ylim([0,35]), grid('on')
title('Dilution of sea water')
xlabel('Time (h)'), ylabel('Salt concentration (g/L)')
However I get the following error:
Array indices must be positive integers or logical values.
Error in seawater>@(t,M)(R*(sin((pi*t)/12))^4+R0)*(Q)-(Q+P)*((M(t))/((V-Q)*t)) (line 13)
f = @(t,M) (R*(sin((pi*t)/12))^4 + R0)*(Q) - (Q+P)*((M(t))/((V-Q)*t));
Error in seawater (line 17)
M(n+1) = M(n) + f(t(n),M(n))*h;
0 件のコメント
回答 (1 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!