Info
This question is closed. Reopen it to edit or answer.
I need help with my code. I don't understand what the error code is for. This is the error code Error: File: Lab1Modeling.m Line: 18 Column: 12 The expression to the left of the equals sign is not a valid target for an assignment.
1 view (last 30 days)
Show older comments
t = 0;
Cai = 4;
Cbi = 1;
P = .15;
A = .85;
N1 = Cai;
N2 = Cbi;
J3 = 0;
count = 1;
while(count < 11)
{
J3 = N1/t;
Ca0 = -(J3/P)+Cai;
count = count+1;
time = time +1;
plot(Ca0, time);
xlabel('Time (sec)');
ylabel('Ca0 (moles)');
if(time = 11)
{
break;
}
0 Comments
Answers (2)
Jacob Ward
on 12 Sep 2019
There are a few problems with your code as written:
First, you are using curly braces instead of using the while/end or if/end syntax that you are supposed to use in MATLAB. You also don't need parentheses for your if and while statement and I think you want a double equals sign for your equals comparison. It should look like this:
if time == 11
break
end
Your while loop should be:
while count < 11
%insert the rest of your code here
end
Finally, you initialize t=0 but I think you meant time=0 because you use the variable 'time' later.
All in all, your code should look like the following:
time = 0;
Cai = 4;
Cbi = 1;
P = .15;
A = .85;
N1 = Cai;
N2 = Cbi;
J3 = 0;
count = 1;
while count < 11
J3 = N1/t;
Ca0 = -(J3/P)+Cai;
count = count+1;
time = time +1;
plot(Ca0, time);
xlabel('Time (sec)');
ylabel('Ca0 (moles)');
if time == 11
break
end
end
0 Comments
madhan ravi
on 12 Sep 2019
% No loops needed:
Cai = 4;
Cbi = 1;
P = .15;
A = .85;
N1 = Cai;
N2 = Cbi;
Start = 0;
End = 11;
Increment = 1; % if you make it small you would get a finer graph
t=Start:Increment:End;
J3 = N1./t;
Ca0 = -(J3/P)+Cai;
plot(Ca0, t,'-ob');
xlabel('Time (sec)');
ylabel('Ca0 (moles)');
0 Comments
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!