%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

madhan ravi
madhan ravi 2020년 9월 16일
Why ask a question if you’re so concerned? Why waste others time?
Rik
Rik 2020년 9월 16일
Comment posted as flag by Paige Macdonald:
i dont want this question posted anymore
Rik
Rik 2020년 9월 16일
That is not an answer to the question Madhan posted. You got free help from a stranger on the internet. Why did you decide to remove your question? You could have simply not posted it. Now you are an inconsiderate jerk taking advantage of friendly people. Is that your intent?
Rik
Rik 2020년 9월 16일
편집: Rik 2020년 9월 16일
Original question as posted by Paige Macdonald, retrieved from Google cache (permalink):
%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."
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일

0 개 추천

You need to index S:
f = -0.5 /(2.1+S(i));

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

태그

질문:

p
p
2020년 9월 16일

편집:

Rik
2020년 12월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by