Some problems about the Numerical Integration

Click For Summary
SUMMARY

This discussion focuses on numerical integration using MATLAB's quadl function, specifically examining five examples that implement the integration of logarithmic functions. The examples utilize a variable a set to 0.1 and a range defined by z=linspace(-0.1,0.1). It is concluded that examples 1, 3, 5, and 6 yield consistent results, while examples 2 and 4 produce different outcomes due to variations in how the function is defined and called. The use of inline and arrayfun in different contexts contributes to these discrepancies.

PREREQUISITES
  • Familiarity with MATLAB programming and syntax
  • Understanding of numerical integration techniques, specifically quadl
  • Knowledge of function handles and anonymous functions in MATLAB
  • Basic concepts of logarithmic functions and their properties
NEXT STEPS
  • Explore the differences between quadl and quad functions in MATLAB
  • Learn about the implications of using inline functions versus anonymous functions
  • Investigate the behavior of arrayfun in MATLAB for vectorized operations
  • Study the mathematical properties of logarithmic functions in numerical integration
USEFUL FOR

Mathematics students, MATLAB users, and researchers involved in numerical analysis and computational mathematics will benefit from this discussion.

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
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
3
Views
4K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 16 ·
Replies
16
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K