Problems using integral function in Matlab

In summary, the conversation discusses a function handle called 'integrando' and its value when used with the 'fplot' and 'integral' functions. There is confusion about the results of the integral, as it is expected to be positive but is instead negative. Parameters such as landa, t, and x0 are mentioned as factors that may affect the function's behavior.
  • #1
cacosomoza
11
0
Hi there!

i have this function handle:

integrando= @(x,landa,t) 1-exp(-((1/(landa*t))*((exp(-landa*x)/x)+((x-x0).*(1+landa*x0)-x0)*(exp(-landa*x0)/(x0^2)))));

which as you can see using

fplot(@(x) integrando(x,3,0.00063),[0 1.1225])

its value is constant (actually 1, and then starts decreasing exponentially until drops to zero at 1.1225). Landa and t are parameters that change the curvature of this drop. Since this is a positive and finite function, I'm waiting a positive integral. However, integrating this same function on this same interval, I get negative figures!

>> q1=integral(@(x) integrando(x,3,0.00063),0,1.1225)

q1 =

-20.3981
This is getting me nuts! I would very much appreciate any help. Thanks in advance!
 
Physics news on Phys.org
  • #2
What value are you using for x0?

I used 2 just to see if the code works, and I got:

integrando= @(x,landa,t) 1-exp(-((1/(landa*t))*((exp(-landa*x)/x)+((x-2).*(1+landa*2)-2)*(exp(-landa*2)/(2^2)))));

fplot(@(x) integrando(x,3,0.00063),[0 1.1225])

q1=integral(@(x) integrando(x,3,0.00063),0,1.1225)

q1 =

1.1225
 
  • #3
hi kreil,

I'm using x0=1.1225 ,which is the same value as the limit of integration. If you try again using that value on 'integrando', you'll see the result of the integral is a negative number which doesn't make any sense to me
 

Related to Problems using integral function in Matlab

1. What is the integral function in Matlab?

The integral function in Matlab is used to calculate the definite or indefinite integral of a given function. It is represented by the "int" or "integral" command and takes in the function and the variables of integration as its input.

2. How do I use the integral function in Matlab?

To use the integral function in Matlab, you first need to define the function and the variables of integration. Then, you can use the "int" or "integral" command to calculate the integral. For example, if you want to calculate the integral of the function f(x) = x^2 from 0 to 1, you would use the command "int(@(x) x^2, 0, 1)".

3. Why am I getting an error when using the integral function in Matlab?

There could be several reasons for getting an error when using the integral function in Matlab. One common reason is that the function or the variables of integration are not properly defined. Another reason could be that the function is not continuous or does not have a finite integral. It is important to check the syntax and ensure that the function and variables are correctly specified.

4. How do I handle singularities when using the integral function in Matlab?

Matlab has built-in functions to handle singularities in the integral function, such as "quad" or "quadgk". These functions use adaptive algorithms to accurately calculate the integral even in the presence of singularities. You can also manually divide the integral into smaller intervals and use the integral function separately for each interval.

5. Can I use the integral function in Matlab for multivariable functions?

Yes, the integral function in Matlab can be used for multivariable functions. You can specify the variables of integration using the "int" or "integral" command and use the proper syntax to define the function. However, it is important to note that the integral function only works for double integrals in Matlab and cannot be used for higher-order integrals.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
27
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • Introductory Physics Homework Help
Replies
5
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
Back
Top