Interpreting Matlab function simp

  • Context: MATLAB 
  • Thread starter Thread starter Ein Krieger
  • Start date Start date
  • Tags Tags
    Function Matlab
Click For Summary

Discussion Overview

The discussion revolves around the interpretation and usage of a custom MATLAB function named `simp`, which is related to numerical integration using Simpson's rule. Participants are exploring how to apply this function to integrate a specific array of values over a defined interval, while clarifying the parameters involved in the function.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant seeks clarification on whether the variable `I1` represents an integration of 21 slices between the boundaries 0 and `r0`.
  • Another participant requests more context and details about the variables used in the provided code snippet.
  • A participant points out that `simp()` is not a standard MATLAB function and suggests checking the function file for input arguments.
  • Information about the `simp` function is shared, detailing its parameters: a function `f`, initial value `a`, end value `b`, and interval size `h`.
  • A participant shares a separate implementation of the `simp` function, raising a question about the use of different variable names (`xl` and `xu`) compared to the original query.
  • Clarifications are made regarding the meaning of the variables `xl`, `xu`, `n`, and `u`, suggesting that `u1d` is integrated from 0 to `r0` using `nr` intervals.
  • There is a question about whether the `simp` function can be applied uniformly to different types of variables, provided the order of arguments is correct.

Areas of Agreement / Disagreement

Participants express uncertainty regarding the specific definitions and roles of variables in the `simp` function, and there is no consensus on the implications of using different variable names. The discussion remains unresolved with multiple interpretations of the function's application.

Contextual Notes

Limitations include the lack of clarity on the definitions of certain variables and the absence of a complete understanding of the `simp` function's implementation as it is not a standard MATLAB function.

Ein Krieger
Messages
32
Reaction score
0
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?
 

Attachments

  • 2.jpg
    2.jpg
    36.9 KB · Views: 550
Physics news on Phys.org
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.
 
Yes. Sure

I have attached all commands with order from Pic.1 to Pic.3
 

Attachments

  • Pic 1.jpg
    Pic 1.jpg
    6.9 KB · Views: 493
  • Pic 2.jpg.png
    Pic 2.jpg.png
    22.4 KB · Views: 578
  • pic 3.jpg
    pic 3.jpg
    26.9 KB · Views: 504
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.
 
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
 
Last edited:
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?
 
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
 
kreil said:
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?
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 3 ·
Replies
3
Views
18K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 3 ·
Replies
3
Views
4K
Replies
2
Views
3K