The Value assigned to variable 'C' might be unused??

7 ビュー (過去 30 日間)
Ian Smith
Ian Smith 2016 年 4 月 20 日
コメント済み: Walter Roberson 2023 年 10 月 31 日
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)

採用された回答

Guillaume
Guillaume 2016 年 4 月 20 日
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 件のコメント
Ian Smith
Ian Smith 2016 年 4 月 21 日
編集済み: Ian Smith 2016 年 4 月 21 日
I entered the code you suggested and this is what comes up:
Error in untitled4 (line 6)
I3 = C(:, 1); I2 = C(:, 2); I1 = C(:, 3);
As a beginner, I am just coming to understand Matlab. I understand some of your points but I still do not understand why this as a whole is not working. Sorry for the inconvenience.
Guillaume
Guillaume 2016 年 4 月 21 日
編集済み: Guillaume 2016 年 4 月 21 日
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.

サインインしてコメントする。

その他の回答 (1 件)

Shu-Han
Shu-Han 2023 年 10 月 31 日
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 件のコメント
Walter Roberson
Walter Roberson 2023 年 10 月 31 日
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
Walter Roberson 2023 年 10 月 31 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by