How to make an anonymous function whose variable is itself a function of another variable?

Let's say i have an anonymous function defined in the following manner
z = @(x) cos(phi).^2 + 4*sin(phi).^2 and phi is defined in the following way
phi = @(x) x.^3 + 4*x.^2 + x +3
I have been trying to do this but when i call the function z in the following way, an error pops up
z(3)
Is something wrong in the syntax?

 채택된 답변

Mischa Kim
Mischa Kim 2014년 5월 23일
편집: Mischa Kim 2014년 5월 23일
Salman, use
phi = @(x) x.^3 + 4*x.^2 + x + 3;
z = @(x) cos(phi(x)).^2 + 4*sin(phi(x)).^2;
z(3)
ans =
1.039526660425723

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2014년 5월 23일

댓글:

2014년 5월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by