Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

EMAE 250 – Computers in Engineering

Lab #1 – MATLAB basics – Pre-lab

Programming Skills Developed

In this assignment, you will practice the following programming skills and program elements: a. following directions

b. creating a public function m-file

c. function input/output

d. using MATLAB built-in functions

e. using the lookfor command

Introduction

For Lab #1 you are going to write a public function that is going to perform a variety of (mostly unrelated) tasks on a square matrix of any size.  However, that is the lab – this is the pre-lab.

Here, you are going to write a much simpler public function script, just to practice the following:

. writing a public function script

. naming your programs properly

. handling different input data structure types

. working with different data transfer methods

. understanding the difference between return and display

You will not have access to the Lab #1 handout until your Pre-lab #1 is actually correct.

Pre-Lab Deliverables

You will upload to Canvas a single MATLAB user-defined public function script titled

LastnameFirstinit_Prelab1.m, the contents and behavior of which are described in the Function   Behavior section below.  Please note that your first letter of your last name, your first initial, and the ‘P’ in Prelab should each be capitalized in the file name.  This matters for the convenience of the grader.

Preparation

I think I covered all of what you need for this assignment in the Week 1 lab session.  You may find the .ppt files in either the MATLAB Module on the Modules page (Introduction to Programming) or on the Pre-lab #1 Canvas assignment page (Prelab #1 Info).

If you ever wish to view .ppt files that I have posted to Canvas, I strongly recommend you download the file and open it in PowerPoint, rather than opening it directly in Canvas, because certain symbols and fonts do not show up properly in Canvas.  Google sheets may work, but I  make no promises.  I generally post a four-slides-per-page .pdf of any .ppt files that I post to

Canvas.  As far as I know, those appear in Canvas properly.  If any symbols do not show up, again download the file and open it in Acrobat.

Function Behavior

Input

Your function script should expect to receive from the calling function the following inputs in this order:

. a character array

. a vector (direction unknown) of two scalar values

. a single scalar value

The string you are passed is the name of a file that contains a square matrix.

Output

Your function script should display to the command window the square root of the scalar value.

Your function script should return to the calling program a column vector containing the following values, in this order:

. the determinant of the square matrix contained within the file

. the product of the two numbers contained in the passed-in array

Special Cases

. your function should work for any size square matrix within the ASCII file to which you are directed

. you need not consider any special cases or check the user input

o the file will contain a square matrix of numbers

o the array will contain two numbers

o the scalar will be positive (although it doesn’t matter, because MATLAB can deal with imaginary and complex numbers)

Hints for Your Code

The format of the file will be ASCII text and the contents of the file are a rectangular 2-D array of numbers.  Therefore, the easiest way to import the matrix from the file is with the MATLAB built-in  load function.  Feel free to enter   help load in the command window and check it out.

MATLAB has a built-in function for calculating the determinant of a square matrix.  Please enter

lookfor determinant into the command window to find it.

Your function may use the MATLAB built-in function   sqrt.