New Reply

Interpreting Matlab function simp

 
Share Thread Thread Tools
Feb27-13, 06:15 AM   #1
 

Interpreting Matlab function simp


Hello, guys

Hey guys,

Got stuck with function integration using Simpson's rule and need your help.

Please first refer to picture attached for full idea of my question:

The Matlab command related to it is:

for i=1:nr

u1d(i)=4.0*pi*r(i)^2*u(it,i)

end

I1=simp(0.0,r0,nr,u1d)/(4.0/3.0*pi*r0^3)

I1 is

nr=21

r0=1.0;

Does it mean that I1 is integrated 21 times between boundaries 0 and r0?
Attached Thumbnails
2.jpg  
PhysOrg.com
PhysOrg
science news on PhysOrg.com

>> Galaxies fed by funnels of fuel
>> The better to see you with: Scientists build record-setting metamaterial flat lens
>> Google eyes emerging markets networks
Feb27-13, 08:12 AM   #2
 
Recognitions:
Gold Membership Gold Member
Can you post more information? The code you posted references variables that you never define. Make it so that your code block can be copy/pasted into matlab.
Feb27-13, 08:27 AM   #3
 
Yes. Sure

I have attached all commands with order from Pic.1 to Pic.3
Attached Thumbnails
Pic 1.jpg   Pic 2.jpg.png   pic 3.jpg  
Feb27-13, 08:46 AM   #4
 
Recognitions:
Gold Membership Gold Member

Interpreting Matlab function simp


simp() is not a matlab function, so the information about the input arguments is not available in the documentation. I suggest looking at the function file for simp() to find this info.
Feb27-13, 09:04 AM   #5
 
Recognitions:
Gold Membership Gold Member
EDIT: I found information about this function in the MATLAB file exchange.

Code:
function s = simp(f, a, b, h)
x1 = a + 2 * h : 2 * h : b - 2 * h;
sum1 = sum(feval(f, x1));
x2 = a + h : 2 * h : b - h;
sum2 = sum(feval(f, x2));
s = h / 3 * (feval(f, a) + feval(f, b) + ...
           2 * sum1 + 4 * sum2);
It appears that the inputs are:

f=function, a=initial value, b=end value, h=interval size
Feb27-13, 04:27 PM   #6
 
I have found it as separate m.file. Here are the commands:

function uint=simp(xl,xu,n,u)
h=(xu-xl)/(n-1);
uint(1)=u(1)-u(n);
for i=3:2:n
uint(1)=uint(1)+4.0*u(i-1)+2.0*u(i);
end
uint=h/3.0*uint;
But why here different variables are used such as xl and xu?

It seems to me that we use r in integration?
Feb27-13, 09:55 PM   #7
 
Recognitions:
Gold Membership Gold Member
At a glance it looks like

xl = beginning of interval
xu = end of interval
n = number of slices
u = function

So in your case of
Code:
I1=simp(0.0,r0,nr,u1d)
You are integrating u1d from 0 to r0 with nr intervals
Feb28-13, 03:50 AM   #8
 
Quote by kreil View Post
At a glance it looks like

xl = beginning of interval
xu = end of interval
n = number of slices
u = function

So in your case of
Code:
I1=simp(0.0,r0,nr,u1d)
You are integrating u1d from 0 to r0 with nr intervals
So you mean simp can be uniformly used for every type of variable assuming their correct order?
New Reply

Tags
integration, matlab, simpson's rule
Thread Tools


Similar Threads for: Interpreting Matlab function simp
Thread Forum Replies
Ramp Function in MATLAB? also window adjustments (MATLAB Help) Introductory Physics Homework 2
Simple structure function - interpreting answer [Probability & Reliability Theory] Calculus & Beyond Homework 0
Interpreting a function based on it's equation. General Math 28
Simp,e Harmonic Motion with Damping Classical Physics 4
Simp Simultaneous Equation Precalculus Mathematics Homework 7