Problems using integral function in Matlab

Click For Summary
SUMMARY

The forum discussion centers on a MATLAB function handle for an integral calculation that yields unexpected negative results. The user defines the function integrando with parameters landa and t, and observes that while the function appears positive when plotted using fplot, the integral computed with integral returns a negative value. The issue arises when using x0 values, particularly when x0=1.1225, leading to confusion about the function's behavior and the validity of the integral.

PREREQUISITES
  • Understanding of MATLAB function handles
  • Familiarity with numerical integration using MATLAB's integral function
  • Knowledge of plotting functions in MATLAB with fplot
  • Basic grasp of exponential functions and their properties
NEXT STEPS
  • Investigate the behavior of MATLAB's integral function with discontinuous functions
  • Learn about the implications of choosing limits of integration in numerical methods
  • Explore MATLAB's error handling for numerical integration
  • Examine the effects of parameter values on function outputs in MATLAB
USEFUL FOR

Mathematics students, MATLAB users, and researchers working with numerical integration and function analysis in MATLAB.

cacosomoza
Messages
11
Reaction score
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
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
 
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
 

Similar threads

  • · Replies 18 ·
Replies
18
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
Replies
27
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 6 ·
Replies
6
Views
4K