MATLAB MATLAB: Solving Simple Integration Problems

AI Thread Summary
In MATLAB, when attempting to perform symbolic integration using the command int(a), users may encounter issues with the output format, particularly with linear functions like x + 6. Instead of providing the expected result of x^2/2 + 6*x, MATLAB returns (x + 6)^2/2, which complicates setting custom integration constants. To address this, users can input polynomial coefficients into a vector for elementwise integration, allowing for a more straightforward output. For more complex symbolic computations, it is suggested to consider using Mathematica, which may offer better functionality for such tasks.
pconn5
Messages
6
Reaction score
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
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?
 

Similar threads

Back
Top