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
 
Thread 'Have I solved this structural engineering equation correctly?'
Hi all, I have a structural engineering book from 1979. I am trying to follow it as best as I can. I have come to a formula that calculates the rotations in radians at the rigid joint that requires an iterative procedure. This equation comes in the form of: $$ x_i = \frac {Q_ih_i + Q_{i+1}h_{i+1}}{4K} + \frac {C}{K}x_{i-1} + \frac {C}{K}x_{i+1} $$ Where: ## Q ## is the horizontal storey shear ## h ## is the storey height ## K = (6G_i + C_i + C_{i+1}) ## ## G = \frac {I_g}{h} ## ## C...
Back
Top