MatLab
 Volume Number: 4 Issue Number: 5 Column Tag: The Workstation Mac

# MatLab Comes to the Mac II

By Paul Zarchan, Cambridge, Mass

## Introduction

MATLAB is an interactive program to help with scientific and engineering numeric calculations. Although it was originally written in FORTRAN for mainframe computers, a second generation MATLAB was rewritten for smaller computers such as the Sun Workstation and the VAX computer. In the last few years a special version of MATLAB was developed to run on MS DOS compatable PC’s with math coprocessors. Typical uses for MATLAB are general purpose numeric computation, algorithm prototyping and solving special purpose problems with matrix formulations that arise in disciplines such as automatic control theory, statistics and digital signal processing. MATLAB is now available for the Mac II or for any Mac souped up with a 68020 accelerator board and a 68881 math coprocessor. For engineers this lends legitimacy to the claim that the Mac II is actually a workstation.

Unlike FORTRAN on the MAC, MATLAB is not really designed to make executable code (i.e. “double clickable” applications). As with interpretive BASIC, the MATLAB application is required on the disk to execute any file previously generated. Unlike BASIC, MATLAB is very fast because of the highly efficient algorithms. MATLAB allows engineers to solve problems almost as they are written mathematically and in addition allows easy access to libraries of some very powerful software. Some have called MATLAB “APL without the pain”. The Mac version of MATLAB takes full advantage of the Mac interface. This also means the MATLAB output can easily be incorporated into reports and presentations making MacMATLAB far more useful than the DOS version.

## Matrix Examples

Matricies can be entered either in the MATLAB editor or by the carrot prompt by using brackets to define the matrix and semicolons to separate matrix rows. For example, by entering

```»A=[1 2 3;4 5 6;7 8 0]
```

we get the MATLAB output on screen as

```A =
1     2     3
4     5     6
7     8     0

```

If we want to find the transpose of matrix A we simply type at the prompt

```»B=A’
```

where the ‘ indicates transposition The resultant screen output is

```B =
1     4     7
2     5     8
3     6     0
```

Taking the matrix inverse of A is simple as typing

```»inv(A)
```

which yields the screen output (nearly instantaneously)

```ans =
-1.7778    0.8889   -0.1111
1.5556   -0.7778    0.2222
-0.1111    0.2222   -0.1111
```

Many other matrix and linear algebra functions are available with MATLAB. Of course, many engineers have these functions built into their FORTRAN libraries - so why use MATLAB? Let’s do more examples to see why!

## Polynomial Example

Suppose we had two polynomials and we wanted to multiply them and find the roots of the resultant expression. If the two polynomials were

x2+3x+2 and x2+x-12

we would define the polynomials in MATLAB by typing

```»A=[1 3 2];
»B=[1 1 -12];
```

where the polynomials are expressed as vectors where the vector elements represent the polynomial coefficients in descending order. We can multiply the 2 polynomials algebraically in MATLAB by using the convolution function or

```»C=conv(A,B)
```

which yields

```»C =
1     4    -7   -34   -24
```

The screen output displays the coefficients of the resultant polynomial in descending order. This means that the product of the 2 polynomials is given by

x4+4x3-7x2-34x-24

To find the roots of the resultant polynomial we simply type

```»roots(C)
```

which yields the 4 roots as

```ans =
3.0000
-4.0000
-2.0000
-1.0000
```

Still not impressed with MATLAB? Let’s look at more examples.

## Plotting

Unlike FORTRAN, plotting functions come built into MATLAB. If we wanted to plot

y=sin(x) and z=.01x2 from -15 to 15 in increments of .05 only the following 4 MATLAB statements would be required

```»x=-15:.05:15;
»y=sin(x);
»z=x.^2/100;
»plot(x,y,x,z)
```

The unenhanced screen output for such a set of commands appears in Fig. 1. Of course since MATLAB grpahical output is in the PICT format it can be copied to the clipboard and pasted into any Macintosh application.

Figure 1 - Plotting With MATLAB is Easy

The graph can be embellished within the MATLAB environment (with features similar to Cricket Graph) or copied onto the clipboard and pasted into MacDraw for further enhancement.

If we wanted to show that a 5 term Fourier series expansion for a square wave is accurate (Gibb’s effect) we only need the following 3 lines of MATLAB code.

```»t = 0:.1:10;
»y = sin(t) + sin(3*t)/3 + sin(5*t)/5 + sin(7*t)/7 + sin(9*t)/9;
»plot(t,y)
```

The resultant unenhanced MATLAB output is shown below.

Figure 2 - MATLAB Output For Gibb’s Effect

Still not impressed? Suppose we wanted to evaluate the function

over the range

-2¾x¾2, -2¾y¾3

All we have to do is use the following 3 MATLAB statements to get a 3 dimensional plot (with all the hidden line algorithms transparent to the user) of the function.

```»[x,y]=meshdom(-2:.2:2,-2:.2:3);
»z=x.*exp(-x.^2-y.^2);
»mesh(z)
```

Figure 3 - MATLAB 3 Dimensional Plot

Incidentally, the plot took only a few seconds to generate. Try doing that in FORTRAN!

## Signal Processing

Noisy signals can be analyzed with MATLAB. For example, we can make 750 gaussian distributed random numbers with zero mean and unity standard deviation with the statements

```»rand(‘normal’)
»y=rand(750,1);
```

We can then analyze and display the frequency content of the 750 random numbers with a MATLAB histogram statement or

```»[n,x]=hist(y);
»plot(x,n,’+’)
```

As expected, the MATLAB output, shown in Fig. 4, demonstrates that the 750 random numbers follow the standard “bell-shaped” curve or well known gaussian distribution.

Figure 4 - MATLAB Can Make Histograms

As was mentioned in the introduction, MATLAB comes with very powerful algorithms. The next example shows a simple use of the FFT (Fast Fourier Transform) function. A common use of the FFT is to find the frequency components buried in a noisy time domain signal. Consider data sampled at 1000 Hz. We can form a signal containing 50 Hz and 120 Hz and corrupt it with gaussian noise (zero mean and unity standard deviation) with the following 5 MATLAB statements.

```»t=0:.001:.5;
»x=sin(2*pi*50*t)+sin(2*pi*120*t);
»rand(‘normal’)
»y=x+2*rand(t);
»plot(y(1:50))
```

Figure 5 - Noisy Signal in Time Domain

It is difficult, if not impossible, to identify the frequency components by looking at the original signal in the time domain. Converting to the frequency domain, the discrete Fourier transform of the noisy signal y is found by taking the FFT. In MATLAB code this means

```»Y=fft(y);
```

The power spectral density, a measurement of the energy at various frequencies, is:

```»Pyy=Y.*conj(Y);
```

We can plot the power spectral density by forming a frequency axis for the first 256 points (the other 256 points are symmetric) with the MATLAB statements

```»f=1000*(0:255)/512;
»plot(f,Pyy(1:256))
```

From the resultant output in Fig. 6 we can clearly see the frequency components at 50 Hz and 120 Hz of the signal.

Figure 6 - Frequency Domain Output

## Control Analysis

MATLAB can also be used in the analysis of control systems from both a modern and classical point of view. We can find and plot the root locus of the transfer function

for gains 0 to 10 in steps of .5 with the following MATLAB statements

```»num = [.2  .3  1];
»den1 = [1 .4 1];
»den2 = [1 .5];
»den = conv(den1,den2);
»k = 0:.5:10;
»r = rlocus(num,den,k);
»plot(r,’x’), title(‘Root-locus’),xlabel(‘Real part’),ylabel(‘Imag part’)
```

The resultant root locus is shown in Fig. 7.

Figure 7 - Root Locus Example With MATLAB

We could find the step response for the same system by typing the additional statements

```»[a,b,c,d] = tf2ss(num,den)
»t = 0:.3:15;
»y = step(a,b,c,d,1,t);
»plot(t,y),title(‘Step response’),xlabel(‘time(sec)’)
```

yielding the output of Fig. 8

Figure 8 - Step Response Output

Another example of the control system analysis capability of MATLAB consider a second order quadratic transfer function with natural frequency 1 rad/sec and damping of .2. The MATLAB program required to display the magnitude characteristics is shown below and the resultant output is displayed in Fig. 9.

```»[a,b,c,d]=ord2(1,.2);
»w=logspace(-1,1);
»[mag,phase]=bode(a,b,c,d,1,w);
»mag1=20*log10(mag);
»semilogx(w,mag1)
```

Figure 9 - Sample Magnitude Bode Plot For Quadratic Transfer Function

## More Details

If you already used MATLAB in the DOS world and have a collection of many files there is no problem in porting them to the MAC. Just use a file transfer program (I used PC to MAC and Back) and the conversion routine (going from ASCII files to .m files) provided by MATLAB. The danger in doing this is that the DOS version of MATLAB will seem very primitive once you have used the MAC version. Incidentally the MAC version of MATLAB runs about 5 times faster than the IBM/AT version and at about the same speed as the Sun-3 Workstation version.

Macintosh MATLAB was developed by The Math Works, Inc. [20 N. Main St., Suite 250, Sherborn, Mass. 01770, (617)653-1415]. The software, including the signal processing toolbox comes on a single 800k disk (unprotected) with a list price of \$895. The control and ientification toolboxes are sold separately - each with a list price of \$495. Although this software is expensive by MAC word processing and spreadsheet standards - it is inexpensive by engineering software standards.

Community Search:
MacTech Search:

## Software Updates via MacUpdate

Capto 1.2.9 - \$29.99
Capto (was Voila) is an easy-to-use app that takes capturing, recording, video and image editing to the next level. With an intelligent file manager and quick sharing options, Capto is perfect for... Read more
Opera 51.0.2830.40 - High-performance We...
Opera is a fast and secure browser trusted by millions of users. With the intuitive interface, Speed Dial and visual bookmarks for organizing favorite sites, news feature with fresh, relevant content... Read more
GarageSale 7.0.13 - Create outstanding e...
GarageSale is a slick, full-featured client application for the eBay online auction system. Create and manage your auctions with ease. With GarageSale, you can create, edit, track, and manage... Read more
1Password is a password manager that uniquely brings you both security and convenience. It is the only program that provides anti-phishing protection and goes beyond password management by adding Web... Read more
Evernote 7.0.1 - Create searchable notes...
Evernote allows you to easily capture information in any environment using whatever device or platform you find most convenient, and makes this information accessible and searchable at anytime, from... Read more
MacUpdate Desktop 6.2.0 - \$20.00
MacUpdate Desktop brings seamless 1-click app installs and version updates to your Mac. With a free MacUpdate account and MacUpdate Desktop 6, Mac users can now install almost any Mac app on... Read more
HoudahSpot 4.3.5 - Advanced file-search...
HoudahSpot is a versatile desktop search tool. Use HoudahSpot to locate hard-to-find files and keep frequently used files within reach. HoudahSpot will immediately feel familiar. It works just the... Read more
EtreCheck 4.0.4 - For troubleshooting yo...
EtreCheck is an app that displays the important details of your system configuration and allow you to copy that information to the Clipboard. It is meant to be used with Apple Support Communities to... Read more
WhatsApp 0.2.8361 - Desktop client for W...
WhatsApp is the desktop client for WhatsApp Messenger, a cross-platform mobile messaging app which allows you to exchange messages without having to pay for SMS. WhatsApp Messenger is available for... Read more
iClock 4.2 - Customize your menubar cloc...
iClock is a menu-bar replacement for Apple's default clock but with 100x features. Have your Apple or Google calendar in the menubar. Have the day, date, and time in different fonts and colors in the... Read more

## Latest Forum Discussions

The best games like Florence
Florence is a great little game about relationships that we absolutely adored. The only problem with it is it's over a little too soon. If you want some other games with some emotional range like Florence, check out these suggestions: [Read more] | Read more »
Angry Birds Champions adds cash prizes t...
Collaborating with developer Rovio Entertainment, GSN Games has released a twist on the Angry Birds formula. Angry Birds Champions features the same bird-flinging gameplay, but now you can catapult Red and co for cash. | Read more »
Around the Empire: What have you missed...
148Apps is part of a family. A big family of sites that make sure you're always up to date with all the portable gaming news. Just like a real family, I guess. I don't know, my mum never told me anything about Candy Crush to be fair. [Read more] | Read more »
The Battle of Polytopia Guide - Tips for...
The addition of multiplayer to The Battle of Polytopia has catapulted the game from a fun enough time waster to a fully-fledged 4X experience on your phone. We've been playing quite a few matches over the past week or so, and we've put together a... | Read more »
All the best games on sale for iPhone an...
Hi there, and welcome to our round up of all the best games that are on sale for iOS at the moment. It's not a vintage week in terms of numbers, but I'm pretty sure that every single one of these is worth picking up if you haven't already played... | Read more »
Disc Drivin' 2 Guide - Tips for the...
We're all still playing quite a bit of Disc Drivin' 2 over here at 148Apps, and we've gotten pretty good at it. Now that we've spent some more time with the game and unlocked more powerups, check out some of these more advanced tips: | Read more »
Alto's Odyssey Guide - How to Tackl...
Alto’s Odyssey is a completely stunning and serene runner, but it can also be a bit tricky. Check out these to try and keep your cool while playing this endless runner: Don’t focus too much on tasks [Read more] | Read more »
Here's everything you need to know...
Alto's Odyssey is a really, really good game. If you don't believe me, you should definitely check out our review by clicking this link right here. It takes the ideas from the original Alto's Adventure, then subtly builds on them, creating... | Read more »
Alto's Odyssey (Games)
Alto's Odyssey 1.0.1 Device: iOS Universal Category: Games Price: \$4.99, Version: 1.0.1 (iTunes) Description: Just beyond the horizon sits a majestic desert, vast and unexplored. Join Alto and his friends and set off on an endless... | Read more »
Vainglory 5v5: Everything you need to kn...
Vainglory just got bigger. [Read more] | Read more »

## Price Scanner via MacPrices.net

Sale! Amazon offers 13″ 2.3GHz MacBook Pros f...
Amazon has 2017 13″ 2.3GHz Apple MacBook Pros on sale today for \$151-\$150 off MSRP, each including free shipping: – 13″ 2.3GHz/128GB Space Gray MacBook Pro (MPXQ2LL/A): \$1148 \$151 off MSRP – 13″ 2.... Read more
Apple AirPods in stock today for \$159, free s...
Adorama reports stock of Apple AirPods today for \$159 including free shipping, plus pay no sales tax outside of NY & NJ. See our Apple AirPod Price Tracker for the latest prices and stock status... Read more
Saturday Sale: Amazon offers 12″ 1.3GHz MacBo...
Amazon has Silver and Gold 2017 12″ 1.3GHz Retina MacBooks on sale for \$250 off MSRP. Shipping is free: – 12″ 1.3GHz Silver MacBook: \$1349.99 \$250 off MSRP – 12″ 1.3GHz Gold MacBook: \$1349.99 \$250... Read more
Use your Apple Education discount and save up...
Purchase a new Mac using Apple’s Education discount, and take up to \$400 off MSRP. All teachers, students, and staff of any educational institution with a .edu email address qualify for the discount... Read more
Apple Canada offers 2017 21″ and 27″ iMacs fo...
Canadian shoppers can save up to \$470 on the purchase of a 2017 current-generation 21″ or 27″ iMac with Certified Refurbished models at Apple Canada. Apple’s refurbished prices are the lowest... Read more
9″ iPads available online at Walmart for \$50...
Walmart has 9.7″ Apple iPads on sale for \$50 off MSRP for a limited time. Sale prices are for online orders only, in-store prices may vary: – 9″ 32GB iPad: \$279.99 \$50 off – 9″ 128GB iPad: \$379.99 \$... Read more
15″ Apple MacBook Pros, Certified Refurbished...
Save \$360-\$420 on the purchase of a 2017 15″ MacBook Pro with Certified Refurbished models at Apple. Apple’s refurbished prices are the lowest available for each model from any reseller. An standard... Read more
Amazon restocks MacBook Pros with models avai...
Amazon has restocked 15″ and 13″ Apple MacBook Pros with models on sale for up to \$251 off MSRP. Shipping is free. Note that stock of some Macs may come and go (and some sell out quickly), so check... Read more
Lowest price of the year: 15″ 2.8GHz Apple Ma...
Amazon has the 2017 Space Gray 15″ 2.8GHz MacBook Pro on sale today for \$251 off MSRP. Shipping is free: – 15″ 2.8GHz Touch Bar MacBook Pro Space Gray (MPTR2LL/A): \$2148, \$251 off MSRP Their price is... Read more
Apple restocks full line of Certified Refurbi...
Apple has restocked a full line of Apple Certified Refurbished 2017 13″ MacBook Pros for \$200-\$300 off MSRP. A standard Apple one-year warranty is included with each MacBook, and shipping is free.... Read more

## Jobs Board

*Apple* Media Products Commerce Engineering...
# Apple Media Products Commerce Engineering Manager Job Number: 56207285 Santa Clara Valley, California, United States Posted: 26-Jan-2018 Weekly Hours: 40.00 **Job Read more
Digital Platforms Lead, Today at *Apple* -...
# Digital Platforms Lead, Today at Apple Job Number: 56178747 Santa Clara Valley, California, United States Posted: 23-Feb-2018 Weekly Hours: 40.00 **Job Summary** Read more
*Apple* Retail - Multiple Positions - Apple,...
Job Description:SalesSpecialist - Retail Customer Service and SalesTransform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
*Apple* Retail - Multiple Positions - Apple,...
Job Description: Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
*Apple* Retail - Multiple Positions - Apple,...
Job Description:SalesSpecialist - Retail Customer Service and SalesTransform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.