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.
댓글 수: 0
답변 (1개)
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 Exchange에서 Camera Views에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!