help w code error

1 次查看(过去 30 天)
p
p 2020-9-16
编辑: Rik 2020-12-14
%Euler's Method
p = 1;
t = 0:p:100;
S = zeros(size(t));
S(1) = 1.000; %initial concentration
n = numel(S); %number of y values (S is y in this case)
disp(' Time Reactant Concentration ')
disp(' (sec) (mol/L) ')
disp(' -------------------------------- ')
%loop to solve the eq
for i=1:n-1
f = -0.5 /(2.1+S)
S(i+1) = S(i) + p * f; %eulers formula
fprintf('6.0f%15.3f\n',t(i), S(i))
end
i am receiving an error for the f = -0.5 /(2.1+S) it says "Error using / Matrix dimensions must agree."
  6 个评论
Rena Berman
Rena Berman 2020-10-8
(Answers Dev) Restored edit
Rik
Rik 2020-12-14
Why did you edit your question again? I will simply revert your edit again. If you want it removed, contact Mathworks. Unless and until I hear from them to leave your edit, I will be reverting it every time you edit this. Why waste your time trying to see if you're more stubborn than me?

请先登录,再进行评论。

回答(1 个)

James Tursa
James Tursa 2020-9-16
You need to index S:
f = -0.5 /(2.1+S(i));

类别

Help CenterFile Exchange 中查找有关 String Parsing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by