MATLAB: Solving Simple Integration Problems

In summary, the user is seeking help with integrating a simple linear function in MATLAB. However, the int(a) function is not giving the desired result. One solution suggested is to put the coefficients of the polynomial into a vector for elementwise integration. The user is also advised to try using Mathematica for symbolic computation instead.
  • #1
pconn5
9
0
I have a question for anyone that is familiar with MATLAB.

I'm trying to do some simple integration in MATLAB (and if your wondering why I don't just do it by hand, it is because I want to implement the same code for a wide variety of functions). The problem is when using int(a) in matlab, it won't integrate a simple linear function such as x+6 with a constant of zero. Instead if I input:

syms x;

int(x+6,x)

The answer is given as (x+6)^2/2, instead of just x^2/2 + 6*x, which almost everything else would do and what I need it to do so I can't set my own integration constants.

Anyone have any help?
 
Physics news on Phys.org
  • #2
Put the coeffs of your polynomial into a vector. It will to an elementwise integration for you:

>> syms x
>> int([x 6])

ans =

[ x^2/2, 6*x]

Despite 'syms', Matlab was not really designed with symbolic computation in mind. If you can, try Mathematica instead. Maybe they have a demo version?
 

Related to MATLAB: Solving Simple Integration Problems

1. How do I set up an integration problem in MATLAB?

In order to set up an integration problem in MATLAB, you will need to define the function you want to integrate and the limits of integration. This can be done using the "syms" function to create symbolic variables and the "int" function to perform the integration.

2. Can I solve multiple integration problems at once in MATLAB?

Yes, MATLAB allows you to solve multiple integration problems at once by using the "arrayfun" function. This function allows you to apply a single function to each element of an array, making it easy to solve multiple integration problems with different limits of integration or functions.

3. How do I plot the graph of an integrated function in MATLAB?

You can use the "ezplot" function in MATLAB to plot the graph of an integrated function. This function takes the integrated function as its argument and automatically generates a graph with the appropriate limits and labels.

4. Can I use MATLAB to calculate definite integrals?

Yes, MATLAB allows you to calculate definite integrals by specifying the limits of integration in the "int" function. This will give you a numerical value for the definite integral of the function within the specified limits.

5. Is there a way to check the accuracy of my integration results in MATLAB?

Yes, you can use the "quadl" function in MATLAB to perform a numerical integration using a more accurate algorithm than the "int" function. This can be helpful in checking the accuracy of your integration results.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
860
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
594
Back
Top