The Value assigned to variable 'C' might be unused??
7 views (last 30 days)
Show older comments
Hi, I am struggling with a piece of code listed below: I am getting the error 'The Value assigned to variable 'C' might be unused' next to the first 'C' equation below Is there any solution. Thank you.
A= [0; 0; 10];
B= [5 -2 0; -3 2 -1; 0 0 1];
C= [I3; I2; I1];
C= linsolve(B,A)
0 Comments
Accepted Answer
Guillaume
on 20 Apr 2016
You create a C matrix by vertically concatenating three matrices/vectors on your first C equation. On the next line, you create a new C matrix by calling linsolve, effectively discarding the C you created on the previous line.
That's what matlab is telling you: you create a C, never use it, and replace it with something else. The solution to your problem depends on your intent. If you did want to use the first C then use a different variable name for the output of linsolve. If you never intended to use that first C, then don't create it.
As a side note, use better variable names anyway, A, B, C, I1, I2, etc. do not tell me anything about the purpose of the variables. Names like numberofpeople, walltemperature, signalfrequency, etc. do.
3 Comments
Guillaume
on 21 Apr 2016
Edited: Guillaume
on 21 Apr 2016
Sorry, I missed the semicolon instead of comma in your C declaration. you're indexing rows not columns, so it should have been:
I3 = C(1, :); I2 = C(2, :); I1 = C(3, :);
But since C is actually a column vector:
I3 = C(1); I2 = C(2); I1 = C(3);
However, much simpler that these unnecessary assignments:
A = [0; 0; 10];
B = [5 -2 0; -3 2 -1; 0 0 1];
C = linsolve(B,A);
D = C - [0; C(1:2)]; %substract nothing from 1st element, 1st from 2nd, 2nd from third
Note that the comments I've made about meaningful variable names, consistency, avoiding numbered variables, etc. are not particular to matlab. They apply to writing code in any language.
More Answers (1)
Shu-Han
on 31 Oct 2023
I keep getting this error message that I don't know how to create the data.
Incorrect use of '=' operator. Assign a value to a variable using '=' and compare values
for equality using '=='.
var C K L w r A;
varexo e;
parameters rho delta gamma alpha lambda g;
alpha = 0.33;
delta = 0.1;
rho = 0.03;
lambda = 0.97;
gamma = 0;
g = 0.015;
model;
1/C= 1/(1+rho)*(1/(C(+1)*(1+g)))*(r(+1)+1-delta);
L^gamma = w/C;
r = alpha*A*(K(-1)/(1+g))^(alpha-1)*L^(1-alpha);
w = (1-alpha)*A*(K(-1)/(1+g))^alpha*L^(-alpha);
K+C = (K(-1)/(1+g))*(1-delta)
+A*(K(-1)/(1+g))^alpha*L^(1-alpha);
log(A) = lambda*log(A(-1))-e;
End;
2 Comments
Walter Roberson
on 31 Oct 2023
To use Dynare you should put the code into a .mod file. To run the code you would go to the command line and
dynare FILENAMEGOESHERE.mod
That will cause the .mod file to be pre-processed into MATLAB and the MATLAB would then be executed
Walter Roberson
on 31 Oct 2023
Should the
+A*(K(-1)/(1+g))^alpha*L^(1-alpha);
line perhaps be on the end of the previous line?
I do not know anything about line continuation in that language.
See Also
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!