Info
此问题已关闭。 请重新打开它进行编辑或回答。
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 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Jacob Ward
2019-9-12
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 个评论
madhan ravi
2019-9-12
% 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 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!