Problem solving a non linear equation using fsolve

1 Ansicht (letzte 30 Tage)
swati tandon
swati tandon am 20 Sep. 2019
Kommentiert: Star Strider am 20 Sep. 2019
I want solve this equation to find Vcp value, and i am expecting Vcp value to be around 80 for the given constants.
options = optimoptions('fsolve');
options.MaxIterations = 1000;
options.MaxFunctionEvaluations = 500;
Po = 1000; % constants
Vin = 90;
Vo = 500;
n = 2;
fsw = 100e3;
Lr = 10e-6;
Cr = 35.29e-9;
Iin = Po/Vin;
Zr = sqrt(Lr/Cr);
Rfl= Vo^2/Po;
fr = 1/(2*pi*sqrt(Lr*Cr));
wr=2*pi*fr;
%% solve for Vcp
eqn = @(Vcp) -2*Vcp + ((Vo/(2*n)) +Vcp)* (1+ sqrt(1-(Iin*Zr/((Vo/(2*n))+Vcp))^2))+ (Iin/Cr)*( (0.5/fsw)- (1/wr)*(pi-asin((Iin*Zr)/((Vo/(2*n))+Vcp))) );
x = fsolve(@(Vcp) eqn(Vcp),80, options);
By using this code, without using options it says the iterations have reached maximum limit.
And if include "options" then NO SOLUTION FOUND.
( fsolve stopped because the relative size of the current step is less than the default value of the step size tolerance squared, but the vector of function values is not near zero as measured by the default value of the function tolerance.)
Could anyone suggest what can i chnage in my code to get the correct result. Any help would be deeply appreciated.
Thanks in advance!

Akzeptierte Antwort

Star Strider
Star Strider am 20 Sep. 2019
If you first vectorise your function:
eqn = @(Vcp) -2.*Vcp + ((Vo./(2.*n)) +Vcp) .* (1+ sqrt(1-(Iin*Zr./((Vo/(2*n))+Vcp)).^2))+ (Iin/Cr)*( (0.5/fsw)- (1/wr)*(pi-asin((Iin*Zr)./((Vo./(2*n))+Vcp))) );
then plot it:
v = linspace(0, 1000);
figure
plot(v, eqn(v))
grid
you will see that it is hyperbolic, has a positive y-asymptote, and never approaches 0 at all. (Note that fsolve is a root finder.) If you expect it to have a root, chack your constants and your function to be certain they are correct. It is also a good idea to plot your function first, so you know what it does.
  2 Kommentare
swati tandon
swati tandon am 20 Sep. 2019
Thank You for answering to my query. So yes there was a sign mistake in the equation.
Star Strider
Star Strider am 20 Sep. 2019
As always, my pleasure.
(I have no idea which sign.)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by