# MuPAD

We first define a differential equation by defining it to be
an equation in the **ode** domain.

>> de:=ode(y'(x)+4*y(x)=exp(3*x),y(x)); ode(4 y(x) + diff(y(x), x) = exp(3 x), y(x))

Note that MuPAD supports the dash notation for the derivative.

>> solve(de); { 3 } { exp(x) } { ------- + C1 exp(-4 x) } { 7 }We can, of course, solve equations with initial conditions:

>> de2:=ode({y''(x)-2*y'(x)+3*y(x)=0,y(0)=1,y'(0)=2},y(x)); ode({D(y)(0) = 2, y(0) = 1, 3 y(x) - 2 diff(y(x), x) + diff(y(x), x, x) = 0 }, y(x)) >> solve(de2); { 1/2 1/2 } { 1/2 exp(x) 2 sin(x 2 ) } { exp(x) cos(x 2 ) + ----------------------- } { 2 }MuPAD will solve linear differential equations with little fuss, and also a large class of non-linear differential equations.

Recurrence relations are solved similarly; by defining an
equation to be of type **rec**, and applying the
command **solve**.

>> rr:=rec(a(n)=a(n-1)+3*a(n-2),a(n)); rec(a(n) = a(n - 1) + 3 a(n - 2), a(n)) >> solve(rr); { / 1/2 \n / 1/2 \n } { | 13 | | 13 | } { a1 | ----- + 1/2 | + a2 | 1/2 - ----- | } { \ 2 / \ 2 / }

If we include initial conditions, MuPAD will return the exact solution.

>> rr2:=rec(a(n)=a(n-1)+3*a(n-2),a(n),{a(0)=1,a(1)=3}); rec(a(n) = a(n - 1) + 3 a(n - 2), a(n), {a(0) = 1, a(1) = 3}) >> solve(rr2); { / 1/2 \ / 1/2 \n / 1/2 \ / 1/2 \n } { | 5 13 | | 13 | | 5 13 | | 13 | } { | 1/2 - ------- | | 1/2 - ----- | + | ------- + 1/2 | | ----- + 1/2 | } { \ 26 / \ 2 / \ 26 / \ 2 / }In the case of a non-homogeneous equation, MuPAD returns the particular solution.

>> rr3:=rec(a(n) = a(n - 1) + 3*a(n - 2)+n^2, a(n)); 2 rec(a(n) = a(n - 1) + 3 a(n - 2) + n , a(n)) >> solve(rr3); { 2 } { 14 n n } { - ---- - -- - 59/27 } { 9 3 }

Graphical display in MuPAD is produced by means of a separate
program called **VCam**, which can be
used entirely independent of MuPAD. But let's suppose we are in the
middle of a MuPAD session (started with xmupad), and we wish to
plot a few functions. The command **plotfunc** will
allow us to plot functions of the form y=f(x), or in three
dimensions, of the form z=f(x,y).

>> plotfunc(1/(1+x^2),x=-4..4); >> plotfunc(x^3-3*x*y^2,x=-2..2,y=-2..2);

Such commands will open up a VCam window with the function displayed in it, and also another window in which it is possible to change various plot options. The output of this second command is shown in Figure 2, along with various of VCams's windows.

**Figure 2. A
Screenshot of VCam in Action**

More general plot commands are **plot2d** and
**plot3d**, by which the above plots can be
generated as follows:

>> plot2d(Mode = Curve, [u, 1/(1+u^2)], u = [-4, 4]]); >> plot3d([Mode = Surface, [u, v, exp(-sqrt(u^2+v^2))], u = [-4, 4], v = [-4, 4]]);

We see that these commands use a parametric representation of the function. This allows for the easy plotting of a large number of different functions. There are a large number of plot options, including colours of plots and backgrounds, style of curves or surfaces, position and style of axes, labels and titles. All these can be changed interactively in VCam, or given as options to the plot command.

For a more complex example, let's plot a torus, with radii 3 and 1. This can be plotted with:

>> plot3d([Mode = Surface, [(3+cos(u))*cos(v), (3+cos(u))*sin(v), sin(u)], u = [0, 2*PI], v = [0, 2*PI]]);

This will give a wireframe torus with three numbered axes—not a particularly elegant result. We can add more options to this basic command to give us a nice filled-in torus with hidden lines, nestling in a box with no numbers:

>> plot3d(Title = "A torus", Axes = Box, Labels = ["","",""], Ticks = 0, [Mode = Surface, [(3+cos(u))*cos(v), (3+cos(u))*sin(v), sin(u)], u = [0, 2*PI], v = [0, 2*PI] Style = [ColorPatches, AndMesh]]);All these options can now be changed again with VCam. We can also change the perspective; zoom in and out; modify the colour scheme; and many other things. We can draw several surfaces at once, by placing multiple surface definitions in the one

**plot3d**command. For example:

>> plot3d(Title = "Two tori", Axes = Box, Labels = ["","",""], Ticks = 0, [Mode = Surface, [(5+cos(u))*cos(v), (5+cos(u))*sin(v), sin(u)], u = [0, 2*PI], v = [0, 2*PI], Style = [ColorPatches, AndMesh] ], [Mode = Surface, [sin(u), 5+(5+cos(u))*cos(v), (5+cos(u))*sin(v)], u = [0, 2*PI], v = [0, 2*PI], Style = [ColorPatches, AndMesh] ] );The result of this is shown in Figure 3.

**Figure 3. Two
Interlocking Tori**

When dealing with such long expressions as this, it is
convenient to first use your favorite editor to create a small
file, say “**tori.mu**”, to contain the above
command, then read it into MuPAD:

>> read("tori.mu");

This obviates using MuPAD's own text editing facilities, which are very basic.

## Geek Guides

Practical (and free!) books for the most technical people on the planet.

- NEW: Get in the Fast Lane with NVMe
- NEW: Take Control of Growing Redis NoSQL Server Clusters
- Linux in the Time of Malware
- Apache Web Servers and SSL Encryption
- Build a Private Cloud for Less Than $10,000!

**Plus many more.**

## Trending Topics

## Upcoming Webinar

### Getting Started with DevOps - Including New Data on IT Performance from Puppet Labs 2015 State of DevOps Report

August 27, 2015

12:00 PM CDT

DevOps represents a profound change from the way most IT departments have traditionally worked: from siloed teams and high-anxiety releases to everyone collaborating on uneventful and more frequent releases of higher-quality code. It doesn't matter how large or small an organization is, or even whether it's historically slow moving or risk averse — there are ways to adopt DevOps sanely, and get measurable results in just weeks.

Free to *Linux Journal* readers.

Django Models and Migrations | Jul 30, 2015 |

Secure Server Deployments in Hostile Territory, Part II | Jul 29, 2015 |

Hacking a Safe with Bash | Jul 28, 2015 |

KDE Reveals Plasma Mobile | Jul 28, 2015 |

Huge Package Overhaul for Debian and Ubuntu | Jul 23, 2015 |

diff -u: What's New in Kernel Development | Jul 22, 2015 |

- Django Models and Migrations
- Hacking a Safe with Bash
- Secure Server Deployments in Hostile Territory, Part II
- Home Automation with Raspberry Pi
- Huge Package Overhaul for Debian and Ubuntu
- The Controversy Behind Canonical's Intellectual Property Policy
- Shashlik - a Tasty New Android Simulator
- Embed Linux in Monitoring and Control Systems
- KDE Reveals Plasma Mobile
- diff -u: What's New in Kernel Development

## Comments

## Sellout

Mupad has been bought out by mathworks and all code is now under matlab (junk) licence.

any and all open source work is now dead.

## Thankyou for a well written a

Thankyou for a well written article. TeXmacs acts as an excellent interface to mupad. I assume that the TeXmacs screen display generated by TeX. The graphics is generated by javaview. The combination of TeXmacs and javaview greatly enhance the mupad experience.