Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: fzero command error
Replies: 3   Last Post: Jun 12, 2014 2:44 PM

 Messages: [ Previous | Next ]
 Radu Bogdan Posts: 2 Registered: 6/10/14
fzero command error
Posted: Jun 10, 2014 3:11 PM

Hello, I am trying to solve an equation using the fzero command and keep getting the following error:

------------------------------------------------------------------------------------------------------------------------
"Operands to the || and && operators must be convertible to logical scalar values.
Error in fzero (line 308)
elseif ~isfinite(fx) || ~isreal(fx)
Error in buck_charge_test_d (line 27)
D=fzero(@(x) d_charge(x,u,A1,B1,A2,B2,Ts,Vref),0.2),"
------------------------------------------------------------------------------------------------------------------------
Now, the function d_charge I use in the main program is the following:
------------------------------------------------------------------------------------------------------------------------
function y=d_charge(x,E,A1,B1,A2,B2,Ts,Vref)
I=eye(3); extr=[0 0 1];
phi1=expm(A1*x*Ts); psi1=inv(A1)*(phi1-I)*B1;
phi2=expm(A2*(1-x)*Ts); psi2=inv(A2)*(phi2-I)*B2;
y=(extr*phi1*inv(I-phi2*phi1)*(phi2*psi1+psi2)+psi1)*E-Vref;
------------------------------------------------------------------------------------------------------------------------
All the variables in the function have been defined and assigned values.
So when I try to execut the function above using the following command line :
D=fzero(@(x) d_charge(x,u,A1,B1,A2,B2,Ts,Vref),0.2),
I always get that error.

Can someone help me ? Thank you in advance.

P.S. If the initialization of the variables and matrixes are needed for better comprehension I will add them ( didn't put them here so this post won't be too big)

Date Subject Author