Borrar filtros
Borrar filtros

The function return value 'value' might be unset.

34 visualizaciones (últimos 30 días)
Benjamin Moak
Benjamin Moak el 8 de Mayo de 2019
Respondida: Star Strider el 8 de Mayo de 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.

Respuestas (1)

Star Strider
Star Strider el 8 de Mayo de 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.

Categorías

Más información sobre Camera Views en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by