|
|
In class, we just started learning how to calculate integrals. So, of course we want to learn how to look at integrals with Matlab. Recall, to assign a symbolic variable, you just have to use the command syms. For example,
>>syms a x
will create two symbolic variables a and x. Then we can calculate an integral using the int command. For example, suppose you want to calculate
This can be done in Matlab via
>> syms x
>> int(x^2,x,0,1)
ans =
1/3
So, what exactly is going on? The first input tells you what you are integrating. In this case, it is the function x^2. The second input is the variable you are integrating with respect to, i.e. x. The third and fourth inputs are your limits of integration. One note of concern using the command int is that there are some functions that an exact solution is unknown. For example, consider the function sin(x^2) from 0 to 1. In this case, Matlab will give you garbage as the answer. To get an approximate solution, just put the command double in front of the int command
>> double(int(sin(x^2),x,0,1))
ans =
0.3103
That's it! Have FUN integrating!!!
|
|