The function return value 'value' might be unset.

34 次查看(过去 30 天)
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.

回答(1 个)

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.

类别

Help CenterFile Exchange 中查找有关 Camera Views 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by