How to put a function in another function?
조회 수: 4 (최근 30일)
이전 댓글 표시
For instance, if there are two functions which are with respect to x: f(x) = x^2 and g(x) = 4*x, I want to make another function using them: h(x) = (f(x)+5*g(x))/(2*f(x)*g(x))
But,
f = @(x) x^2;
g = @(x) 4*x;
h = @(x) (f+5*g)/(2*f*g);
doesn't work.
Is there any way to do this?
댓글 수: 0
채택된 답변
Geoff Hayes
2016년 3월 21일
Yusuke - if x is the input parameter to your function h, then you must pass this into f and g as well. So instead of
h = @(x) (f+5*g)/(2*f*g);
you would write
h = @(x) (f(x)+5*g(x))/(2*f(x)*g(x));
Try the above and see what happens!
추가 답변 (1개)
the cyclist
2016년 3월 21일
You have to supply the function arguments:
h = @(x) (f(x)+5*g(x))/(2*f(x)*g(x));
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!