I don't understand why This code doesn't work ----error

i want to solve this problem... here is my code...
This doesn't work saying "??? Undefined function or method 'power' for input arguments of type 'function_handle'."
please help me...
I have constant of R,th,C00 and so on
diC1=@(z) (((2*pi*e0)*((R^2)*(1-sin(th)))/((z)*(z)+R*sin(th))));
Call1=@(z) 2*pi*e0*R*log(1+R*(1-sin(th))/z)+C00;
Re1=@(z) ((diC1)*(j/(2*pi*f*(Call1).^2))*(yab/((1+yaa*Rs)*(1+ybb*ZL)-(yab)^2*Rs*ZL))...
-yab*ZL*(ybb+yaa*ybb*Rs-yab^2*Rs)/((1+yaa*Rs)*(1+ybb*ZL)-yab^2*Rs*ZL)^2);%*(z(i)-z0);
z=0:0.1:10;
plot(z,Re1(z))

댓글 수: 1

Adam
Adam 2017년 3월 16일
Using just 'j' and 'i' should work fine for complex numbers, but it is recommended to use 1j or 1i for complex numbers. This isn't related to your error, just a comment based on the discussion in Torsten's answer.

댓글을 달려면 로그인하십시오.

 채택된 답변

Adam
Adam 2017년 3월 16일
편집: Adam 2017년 3월 16일
Your function handles take z as an argument so you need to pass this in and actually call the function
Re1=@(z) ((diC1)*(j/(2*pi*f*(Call1).^2))...
does not actually call your functions diC1 and Call1, it puts the function handle itself into the mathematical expression. This is why you get the error that power is not defined for function_handle inputs because you are trying to effectively do:
Call1.^2
and square the function handle.
You should replace this with:
Re1=@(z) ((diC1(z))*(j/(2*pi*f*(Call1(z)).^2))...
and the same for any other function handle calls that I missed. Even if the function handles don't take an argument you still need to use
diC1()
to actually execute the function because otherwise the function handle itself is a variable and can be passed around as such, but cannot be used in mathematical expressions without being actually called as above.

추가 답변 (1개)

Torsten
Torsten 2017년 3월 16일
diC1= (((2*pi.*e0).*((R.^2).*(1-sin(th)))./((z).*(z)+R.*sin(th))));
Call1= 2*pi.*e0.*R.*log(1+R.*(1-sin(th))./z)+C00;
Re1= ((diC1).*(j./(2*pi.*f.*(Call1).^2)).*(yab./((1+yaa.*Rs).*(1+ybb.*ZL)-(yab).^2.*Rs.*ZL))...
-yab.*ZL.*(ybb+yaa.*ybb.*Rs-yab.^2.*Rs)/((1+yaa.*Rs).*(1+ybb.*ZL)-yab.^2.*Rs.*ZL).^2);%*(z(i)-z0);
z=0:0.1:10;
plot(z,Re1)
Of course, all variables you use have to be defined in advance.
Is "j" supposed to be the imaginary unit ?
Best wishes
Torsten.

댓글 수: 3

Junho Ban
Junho Ban 2017년 3월 16일
편집: Junho Ban 2017년 3월 16일
yes 'j' is the imaginary unit...and all variables are defined.
Then you can only plot real and imaginary part of Re1 separately.
plot(z,imag(Re1))
e.g.
Best wishes
Torsten.
thanks for your tip!!!!!!!!!!!!! :)

댓글을 달려면 로그인하십시오.

태그

질문:

2017년 3월 16일

편집:

2017년 3월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by