Incorrect use of '=' operator. Assign a value to a variable using '=' and compare values for equality using '=='.
5 views (last 30 days)
Show older comments
Asking for help.
File: trycurvefitI.m Line: 45 Column: 17
ERROR "Incorrect use of '=' operator. To assign a value to a variable, use '='. To compare values for equality, use '=='."
I already followed instruction above but my dcdt(2) plot become a linear line.Any little suggestion or solutions or comments are very welcomed! Thank you so much!
This is my code
function trycurvefit
function C=kinetics(theta,t)
c0=[0.1143; 0.9659; 0.04406];
[T,Cv]=ode45(@DifEq,t,c0);
%
function dC=DifEq(t,c)
z = [1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20];
j = 1;
for j = 1 : 20
if z(j) <= 4
I = 45;
elseif z(j) <= 7
I = 90;
elseif z(j) <= 11
I = 120;
elseif z(j) <= 15
I = 150;
else
I = 180;
end
dcdt=zeros(3,1);
dcdt(1)= (theta(1).*(c(2)/(theta(2)+c(2)+(c(2).^2/theta(3))))*(I/(theta(4)+I)).*(1-c(1)/theta(5)).*(1-c(3)/theta(6)));
-dcdt(2)=(1/theta(7).*dcdt(1))+(1/theta(8).*dcdt(3))+(theta(9).*c(1));
dcdt(3)= (theta(10).*dcdt(1)+theta(11).*c(1)).*(c(2)./(theta(12)+c(2)+(c(2).^2/theta(13)))).*(c(3)/(theta(14)+c(3))).*(I/(theta(15)+I));
dC=dcdt;
end
end
C=Cv;
end
0 Comments
Answers (1)
Steven Lord
on 24 Oct 2021
-dcdt(2)=(1/theta(7).*dcdt(1))+(1/theta(8).*dcdt(3))+(theta(9).*c(1));
Assigning to element 2 of the variable dcdt is allowed.
Assigning to the expression -dcdt(2) is not allowed.
Either eliminate the - entirely or move it to the right side (essentially multiply both sides of the line of code by -1.)
5 Comments
Steven Lord
on 25 Oct 2021
I'm guessing that you're not specifying the tspan vector as a vector with more than 2 elements to evaluate the solution of the ODEs at the times for which you have data that you're trying to fit the curve. See these documentation pages:
- https://www.mathworks.com/help/optim/ug/fit-ode-problem-based-least-squares.html
- https://www.mathworks.com/help/optim/ug/fit-differential-equation-ode.html
- https://www.mathworks.com/help/optim/ug/optimizing-a-simulation-or-ordinary-differential-equation.html
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!