Re: Embedded Matlab in Simulink to find a zero by bisection method





Mike, I didn't understand where is my error.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function b = find_b(k,p_inf,Gamma_0,b1,b2)
% This block supports the Embedded MATLAB subset.
% See the help menu for details.

bc=0;
while abs(b1-b2)>0.1
f1=-1/4*b1+k*b1^2/4*p_inf-k*b1^2/4+k*b1/2+b1/2-(Gamma_0^2./
(8*pi^2.*b1))/k;
f2=-1/4*b2+k*b2^2/4*p_inf-k*b2^2/4+k*b2/2+b2/2-(Gamma_0^2./
(8*pi^2.*b2))/k;
bc=(b1+b2)/2;
f=-1/4*bc+k*bc^2/4*p_inf-k*bc^2/4+k*bc/2+bc/2-(Gamma_0^2./
(8*pi^2.*bc))/k;
if f>0 && f1>0
b1=bc;
elseif f>0 && f2>0
b2=bc;
end
if f<0 && f1<0
b1=bc;
elseif f<0 && f2<0
b2=bc;
end
end
b=bc;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Now a 'b' value is given but it's simply the difference between b1 and
b2
b1=50
b2=0.1
The while condition, 'abs(b1-b2)<0.1' is satisfied, but the script
doesn't seem go into the cycle.
I'd like a infinite loop than this dummy result !

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% How would you correct my script to find the zero of the 'function
f' in [b1 b2] interval by a Embedded Matlab subset? %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
.



Relevant Pages