The function return value 'value' might be unset.

12 Ansichten (letzte 30 Tage)
Benjamin Moak
Benjamin Moak am 8 Mai 2019
Beantwortet: Star Strider am 8 Mai 2019
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.

Akzeptierte Antwort

Star Strider
Star Strider am 8 Mai 2019
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.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by