Dynamic optimization with three functions, where two of them are subfunctions.
2 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I am currently working on a excercise sheet on Matlab-functions, and I am having difficulties to code a function the way it is supposed to work. Basically I have 3 functions, where 2 of them are subfunctions.
The first function:
function c = nutzen(S,x,W)
c = 7 * min(S+x,W) - 2*x-3*(x>0)-1*max(0,S+x-W)
end
The second function:
function Sneu = transformationsfunktion(S,x,W)
Sneu = max(0,S+x-W)
end
Then, both of them need to be incorporated into the third:
function V = wertfunktion(S,t)
if t==0
V = 0
end
W = 3
for x = 0:10
v(x) = nutzen(S,x,W) + wertfunktion(transformationsfunktion(S,x,W),t-1)
end
V = max(v(x))
end
To start this code, I have to give values for S and t, but afterwards the code gets into an endless loop...
Actually, it should for x=0:10 calculate the value for v(x) and then after 11 loops give me the max value. Seems to be quite simple.
Does anyone see where my mistake is?
Any help is much appreciated.
11 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Surrogate Optimization についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!