The function return value 'value' might be unset.

14 ビュー (過去 30 日間)
Benjamin Moak
Benjamin Moak 2019 年 5 月 8 日
回答済み: Star Strider 2019 年 5 月 8 日
I'm trying to make a code that uses Euler's method into a function that can be called later. This is the original, which works as intended.
K = 167; H = 100; Te = 20; w = 0.01; T(1) = 100;
t = 0.001; L = 0.4; A = w*t; P = 2*w + 2*t;
h = 0.1/100; x = [0:h:0.4];
V = -21277.8;
Tprime = @(V)V;
Vprime = @(T) (H*P*(T-Te))/(K*A);
for k = 1:length(x)-1
T(k+1) = T(k) + h*Tprime(V(k));
V(k+1) = V(k) + h*Vprime(T(k));
end
TL = T(k)
T(1:5)
And this is my attempt at making it into a function that can be called.
function value = Problem2B(V)
K = 167; H = 100; Te = 20; w = 0.01; T(1) = 100;
t = 0.001; L = 0.4; A = w*t; P = 2*w + 2*t;
h = 0.1/100; x = [0:h:0.4];
V = -21277.8;
Tprime = @(V)V;
Vprime = @(T) (H*P*(T-Te))/(K*A);
for k = 1:length(x)-1
T(k+1) = T(k) + h*Tprime(V(k));
V(k+1) = V(k) + h*Vprime(T(k));
end
TL = T(k)
T(1:5)
Problem2B = TL
end
But it gives me the error when I try to call it in other .m files.

採用された回答

Star Strider
Star Strider 2019 年 5 月 8 日
Your function returns the variable ‘value’, however you never assign anything to ‘value’ in your function (at least not that I can see).
It seems that you want to return ‘T’ or ‘TL’. Consider assigning one of them to ‘value’.
Also, this line could cause problems:
Problem2B = TL
It would be best to delete it.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by