Some problems about the Numerical Integration

AI Thread Summary
The discussion centers on issues encountered with numerical integration in MATLAB using the `quadl` function across five examples. Examples 1, 3, 5, and 6 yield consistent results, while examples 2 and 4 produce different outcomes. The discrepancies may arise from the way functions are defined and evaluated in the different examples, particularly with the use of inline functions and string concatenation. Participants are seeking clarification on why these variations occur and how to ensure consistent results across all examples. Understanding the nuances of function handling in MATLAB is crucial for resolving these integration issues.
sigma665
Messages
2
Reaction score
0
there are 5 examples as follows:

%%% example01 %%%%
z=linspace(-0.1,0.1);
a=0.1;
kesi=(z+sqrt(z.^2-a^2))./a;
for j=1:length(z)
f=@(b) log(1-((b+sqrt(b.^2-a^2))./a)./kesi(j));
I(j)=quadl(f,-0.1+eps,0.1+eps,1e-8);
end

%%% example02 %%%%
z=linspace(-0.1,0.1);
a=0.1;
kesi=(z+sqrt(z.^2-a^2))./a;
for i=1:length(z)
k=kesi(i);
fun=strcat('log(1-((b+sqrt(b.^2-0.1^2))./0.1)./',num2str(k),')');
II(i)=quadl(inline(fun),-0.1+eps,0.1+eps);
end

%%% example03 %%%%
z=linspace(-0.1,0.1);
a=0.1;
kesi=(z+sqrt(z.^2-a^2))./a;
for i=1:length(z)
k=kesi(i);
fun=inline(subs('log(1-((b+sqrt(b^2-0.1^2))/0.1)/kesi)','kesi',k));
III(i)=quadl(fun,-0.1+eps,0.1+eps);
end

%%% example04 %%%%
z=linspace(-0.1,0.1);
a=0.1;
kesi=(z+sqrt(z.^2-a^2))./a;
ff=@(k) ['log(1-((b+sqrt(b.^2-0.1^2))./0.1)./',num2str(k),')'];
f=@(k) quadl(ff(k),-0.1+eps,0.1+eps);
for i=1:length(z)
IIII(i)=f(kesi(i));
end

%%% example05 %%%%
clear all;clc;
a=0.1;
f=@(kesi) quadl(@(b) log(1-((b+sqrt(b.^2-a^2))./a)./kesi),-0.1+eps,0.1+eps)
z=linspace(-0.1,0.1);
kesi=(z+sqrt(z.^2-a^2))./a;
y=zeros(size(z));
for ii=1:length(z)
IIIII(ii)=f(kesi(ii));
end

%%example06 %%%%
a=0.1;
z=linspace(-0.1,0.1);
kesi=(z+sqrt(z.^2-a^2))./a;
IIIIII=arrayfun(@(kesi) quad(@(b) log(1-((b+sqrt(b.^2-a^2))./a)./kesi),-0.1+eps,0.1+eps),kesi);


example 1,3,5,6 get the same results, but 2,4 get the anoth results.

anybody know why?
 
Physics news on Phys.org
please help.....
thanks
 
Back
Top