Reputation: 11
How can I calculate the volume of the integral
x = sqr(siny), 0<=y<=pi, X = 0, y = 4`
I know to plug in
int(sym('2*pi*sin(y)*exp(1/2)'),0,pi)
But I don't know how to set the bounds.
Upvotes: 0
Views: 358
Reputation: 4558
Assuming that an integral in Matlab works the same way as the integral operator does in maths there should be simple to solve. So in maths the expression
I = int(f(x),a,b),
calculates the integral between the closed bounds [a,b]
. The Matlab equivalent is
syms x;
a = 0; % Example values
b = pi;
y = x^2;
I = int(y,0,pi); % I is a sym.
IDouble = eval(I);
So I is still a sym, but if you want the value as a double you can evaluate the expression with eval
(which is not the same eval
as is used for eval('a=1;')
). However, the math expression
F(x) = int(f(x)),
calculates the primitive function or indefinite integral. The matlab equivalent of this is
syms x;
y = x^2;
Y = int(y);
where Y
is the primitive function of y
. This can then be plotted with the plot function for symbolic expressions ezplot
. Try to plot above code with the command ezplot(Y,-1,6);
. As for assuming Matlab automatically plots an integral after calculating it, you should not do that. Matlab is mainly created for complicated functions (maybe with no analytic solution or a too long or complicated solution to be able to do by hand). This means that the numerical/symbolic/plotted output may not necessarily be of interest. The interesting output may be the result of several complicated calculations and this may be the only output wanted. If Matlab by default subsequently generated plots for every step, this would be extremely annoying. It would also compromise the reputation Matlab tries to build being a general purpose programming language.
Upvotes: 2