Professional Documents
Culture Documents
and Mupad
Daya
Shankar
(
Ph.D.
)
Daya Shankar ( Ph.D. )
Dept.
of
Mechanical
Engineering
Dept. of Mechanical Engineering
iitdaya@hotmail.com
Topic Covered:
Understand the difference between numeric and symbolic
computing.
Learn about the capabilities of the symbolic math toolbox.
Practice using the symbolic math toolbox, transitioning
between symbolic and numeric computations.
MATLAB tool box Mupad
>> sqrt(2)
ans = 1.4142
>> var = sqrt(sym(2))
var = 2^(1/2)
>> double(var)
ans = 1.4142
>> sym(2)/sym(5) + sym(1)/sym(3)
ans = 11/15
% f = cos(th)
% ans = -1
% ans = m
% ans = 1
>> p = sin(th)^n
>> diff(p, th)
% p = sin(th)^n
% ans = n*cos(th)*sin(th)^(n - 1)
>> clear
>> syms m b x
>> y = m*x + b;
Indefinite integrals
>> int(y, x)
>> int(y, b)
>> int(1/(1+x^2))
Definite integrals
>> int(y,x,2,5)
>> int(1/(1+x^2),x,0,1)
>> clear
>> syms a b c d x
>> solve('a*x^2 + b*x + c = 0')
ans =
% Quadratic equation!
-(b + (b^2 - 4*a*c)^(1/2))/(2*a)
-(b - (b^2 - 4*a*c)^(1/2))/(2*a)
>> solve('a*x^3 + b*x^2 + c*x + d = 0')
Nasty-looking expression
>> pretty(ans)
Debatable better-looking expression
From in-class 2:
>> solve('m*x + b - (n*x + c)', 'x')
>> solve('m*x + b - (n*x + c)', 'b')
>> collect(ans, 'x')
clear; syms x y
ezplot( 1 / (5 + 4*cos(x)) );
hold on; axis equal
g = x^2 + y^2 - 3;
ezplot(g);
% character this
always refers to the
result of the last
calculation that
Mupad has
done.
Mupad has lots of built in special
functions, which can be very useful.
Notice also that, unlike MATLAB,
Mupad returns the correct answer for
sin(PI). This is because by default,
Mupad is not working with
floating point numbers.
You can save your work in a Mupad Notebook (a bit like a MATLAB
script) by going the the File>Save menu.
The file should be saved with the default .mn extension.
To insert a text paragraph, just hit the button, or use Insert>Text
Paragraph.
Use Insert> Calculation to go back to typing in math, or use the
button.
You can also export a Mupad notebook to html or pdf format, if you
want to publish your work.
Mupad is quite
good at doing
algebra. For
example, it can
solve equations
Because there are two
solutions, they are
returned in a set (enclosed
by {}). You can extract
each one by
using the [number]
convention.
If you want to clear all variables, you can use the reset function
Lets try some more algebra
Plotting
3D Plot
you may also make very fancy looking
plots
Mupad can do
parametric plots
as well, in both
2D and 3D. Try
this