how to decrease the tolerence or accuracy of my results

2 views (last 30 days)
Youseff on 14 Feb 2014
Answered: Mike Hosea on 14 Feb 2014
i have a hard integral problem , and i would like to decrease its tolerence , i read about abstol and reltol but ive been unable to use them. the value of the 4371875181445801/9007199254740992 , which is rediculous what i need is to probably 3 decimal places. my code is below only the last coulple of lines are the actual double integration.
TT= T/4; for t=0:T: TT %time is equal to zero since the power is measured , and later on this value might be changed making a 3d pressure dist over time. ask for timeperiod imaginary= sqrt(-1); for qqq= 1 : N u_n= Amplitude*(exp(imaginary*((w*t)+phi_i(qqq)))); %complex excitation of each element
UU= [u_n u_n]; U= [U;UU];
U(1, :)= []; %this will cut out the first row which is random numb and one of the colomns U(:, 2)= []; %%Finding h Width_x= (xmaxfield-xminfield)/(no_grid_x); Width_y= 0; Width_z= (zmaxfield-zminfield)/(no_grid_z); Area= Width_x*Width_z; y_maxtwo= sqrt(((diameter_element/2)^2)-((x-x_element(qqq))^2)) -2;
for ppp= 1: no_grid_x for pppp= 1: no_grid_z %q for numerical value %summation sum(f, i = a..b) tries to find a closed form representation of the sum . syms zz rmn dr_dy dr_dx x y zz= @(x,y) r_a-(r_a cos((asin(((sqrt((x.^2)+(y.^2)))-b)/r_a)))); INT = ((i*density*c1*k)/(2*pi)); %constant in hmn before the integration rmn= @(x,y) sqrt((((x-x_field(ppp)).^2)+((y-y_field).^2))+((zz(x,y) -z_field(pppp)).^2)); dr_dy= @(x,y) ((y)/(((x)^2)+((y)^2))); %dr/dy dr_dx= @(x,y) (x)/(((x)^2)+((y)^2)); %dr/dx %p_mn1= integral2((exp((-imaginary*k*rmn)-phi_i(qqq)/rmn))(sqrt(((dr_dy)^2)+((dr_dx)^2)+1)),x_min,x_max) %p= dblquad(@(x_t,y_t)((exp((-imfunaginary*k*rmn)-phi_i(qqq)/rmn))*(sqrt(((dr_dy)^2)+((dr_dx)^2)+1))), x_min(qqq), x_max(qqq),y_min(qqq), sqrt((((diameter_element/2)^2)-(x_t-x_element)^2))-2 )
%p_mn2 = @(x,y)exp((-imaginary*k*sqrt(((x-x_field(ppp)).^2)+((y-y_field).^2)+((r_a- (r_a cos((asin(((sqrt((x.^2)+(y.^2)))-b)/r_a))))-z_field(pppp)).^2)))-phi_i(qqq)/sqrt(((x-x_field(ppp)).^2)+((y-y_field).^2)+((r_a- (r_a *cos((asin(((sqrt((x.^2)+(y.^2)))-b)/r_a))))-z_field(pppp)).^2)))(sqrt(((y/(((x)^2)+((y)^2)))^2)+((x/(((x)^2)+((y)^2)))^2)+1)); %p_mn1 = integral2(p_mn2, x_min(qqq), x_max(qqq),y_min(qqq), y_maxtwo); %integration q = integral2(fun,xmin,xmax,ymin,ymax) fun(x,y) , first_int= int((exp(((-imaginary*k*rmn(x,y))-phi_i(qqq))/rmn(x,y)))*(sqrt(((dr_dy(x,y))^2)+((dr_dx(x,y))^2)+1)),x, x_min(qqq),x_max(qqq)); second_int= int(first_int, y, y_min(qqq), y_max(qqq)); p_mn = INT*second_int; PMN_N= [p_mn p_mn]; PMN= [PMN ;PMN_N];
end end end end
  1 Comment
Jan on 14 Feb 2014
Please, Youseff, format your code properly, such that it is readable.

Sign in to comment.

Answers (1)

Mike Hosea
Mike Hosea on 14 Feb 2014
Youseff, I did not try to read your code, but I see integral2() in there, and you mention not knowing how to use reltol and abstol. Check out Loren's blog on the subject here:
Also, there's a follow-up now that might be of some interest as well:


Community Treasure Hunt

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

Start Hunting!