Make a function as the input of a function for iterative computing

2 次查看(过去 30 天)
Hi everyone,
I would like to know how to make a function as the input of a function in matlab. In fact, I want to solve g(x1,x2) from the equation g(x1,x2) = f(x1,x2,g(y1,y2)) by iteration method. The function g is reused as an input of the function f at each iteration step. So I encounter with the problem of making a function as the input of a function.
Can you tell me how to do it? Thank you in advance for your help!!!
Tuan

回答(1 个)

Matt J
Matt J 2012-10-14
You can do it exactly as you've written it. When you execute f(x1,x2,g(y1,y2)) in MATLAB, the output of g(y1,y2) will be fed into f() as its 3rd argument.
  2 个评论
Tuan
Tuan 2012-10-14
编辑:Tuan 2012-10-14
Hi Matt,
Thank you so much for your prompt answer. Actually, I would like to run this code:
function out=func(x,y,a,b) global s s=1; for i=2:4 out(i)=g(x,y,a,b); s=s+1; end end
function out=g(x,y,a,b) global s if s==1 out=x+y; else out=f(a,b); end end
function out=f(a,b) out=dblquad(@(x,y) g(x,y,a,b),0,a,0,b); end
Matlab shows me the error: ??? Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N) to change the limit. Be aware that exceeding your available stack space can crash MATLAB and/or your computer.
Error in ==> func>g
Can you tell me how to overcome this problem? Thank you!
Tuan
Matt Fig
Matt Fig 2012-10-14
Tuan, you must already know that it would help immensely if you showed the actual error message! The more information you give, the quicker we can help...

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by