Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Program fails for lower values of g ; fsolve gives tolerance error ; integral dont converge

1 vue (au cours des 30 derniers jours)
Lucas Pollito
Lucas Pollito le 10 Mai 2015
Clôturé : MATLAB Answer Bot le 20 Août 2021
i want to calculate de qQd value, for a lower value of g, like this :
%angulo espalhamento
function exem6
tic
f=@(b) anggbsR(b);
x0=[1,2];
x=fzero(f,1.1);
T=100;
g=0.2;
f1=@(b) 2*(1 + (sqrt(pi*T)/(2*g)).*sin(ang2(b)/2)).*b ;
f2=@(b) 2*(1 - cos(ang2(b))).*b ;
T=100;
qQd = integral (f2,x, 10,'RelTol',0,'AbsTol',1e-7) + integral(f1,0,x)
toc
end
function Res = qQd(g)
f=@(b) anggbsR(b);
%x0=[1,2];
x=fzero(f,1.1);
%T=100;
g=0.2;
T=100;
f1=@(b) 2*(1 + (sqrt(pi*T)/(2*g)).*sin(ang2(b)/2)).*b ;
f2=@(b) 2*(1 - cos(ang2(b))).*b ;
Res = integral (f2,x, 10,'RelTol',0,'AbsTol',1e-7) + integral(f1,0,x);
end
function xx2 = ang2(b)
for i=1:length(b)
xx2(i)=anggbsR(b(i));
end
end
function xx=anggbsR(b)
g=0.2;
T=100;
s= 1;
R= 2;
syms r
func = @(r) 1 - (b/r)^2 - (g^-2)*(2/15*[(s/R)]^9 *(1/(r - 1)^9 - 1/(r + 1)^9 - 9/(8* r)*(1/(r - 1)^8 - 1/(r + 1)^8)) - [(s/R)]^3 *(1/(r -1)^3 - 1/(r + 1)^3 - 3/(2* r)* (1/(r - 1)^2 - 1/(r + 1)^2)));
minrootgbsR = fzero(func,1.1);
k=1;
for i=1:length(minrootgbsR)
if(isreal(minrootgbsR(i))==1)
vec(k)=minrootgbsR(i);
k=k+1;
end
end
fun =@(r) 1./(r.^2 .* sqrt(1 - (b./r).^2 - (g^-2)*(2/15*(s/R)^9 *(1./(r - 1).^9 - 1./(r + 1).^9 - 9./(8* r).*(1./(r - 1).^8 - 1./(r + 1).^8)) - (s/R)^3 *(1./(r -1).^3 - 1./(r + 1).^3 - 3./(2* r).* (1./(r - 1).^2 - 1./(r + 1).^2)))));
xx = real ( pi - 2*b * integral(fun,max(vec),Inf));
end
for g=0.02 , this integral doesnt work, but for g=10, for example, works great. fsolve gives a tolerance error .. fzero dont work. What Happened ? solver integral
  2 commentaires
Walter Roberson
Walter Roberson le 11 Mai 2015
Note: in anggbsR you have
syms r
but you never use r as a symbol. When you use
func = @(r) .....
then r because a local parameter just as if you had written
function value = func(r)
...
end
and it "shadows" the meaning of r as a symbol. Another term for this is "dummy variable"
Walter Roberson
Walter Roberson le 11 Mai 2015
I had to do a lot of clean up of the indentation to make it readable. Please use the "smart indentation" feature of the MATLAB code editor on your code. It was difficult to tell where some of your variables where coming from because of the indentation you had used.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by