What is the difference between a script and function

Assignment Help MATLAB Programming
Reference no: EM131218071

Pre-Lab

Objectives

? Learn how to use various MATLAB built-in functions

? Become familiar with vector and matrix multiplication in MATLAB

The input function is a MATLAB built-in function that allows a program to accept user input. For example, if one wanted to ask the user to enter a number between 1 and 5, the MATLAB code would look like:

some_num = input(‘Enter a number between 1 and 5')

This code would ask the user to enter a number between 1 and 5, and store the input number in the some_num variable. You may be wondering what the single quotes are. In MATLAB, single quotes denote a string. A string is a sequence of characters, such as ‘dog', and ‘ate my homework!'. For the purposes of this lab, you can consider a string to simply represent text.

1) Based on the information above, write the MATLAB code to ask the user to enter a velocity in m/s. Be sure to store the input in a variable that has a fitting name.

One can also do element-wise multiplication with vectors and matrices in MATLAB (Hadamard product). It is, however, different syntax than multiplying scalar values. For example, if we wanted to multiply a vector x by the scalar 4 (in other words, scale the vector by 4), we would simply write the code 4 * x. This syntax does not work if we want to multiply x by another vector, say y. In order to do element-wise multiplication for vectors and matrices, we need to add a dot to our mathematical operator. Instead of x * y, we would write the code x .* y. The need for the .next to the operator is only necessary for multiplication and division. Addition and subtraction follows the normal, conventional syntax.

2) You have two Matrices, A and B. Assume that they are the correct dimensions (i.e. Both rows and columns are equal). Write the MATLAB code to do the following.

a) Add A and B

b) Subtract B from A

c) Multiply A and B

d) Divide B by A

e) A Cubed (Hint: remember that A raised to the third power is the same as A times A times A)

3) Scripts and functions (also known by their extension as .m files) are ways of organizing code in units or modules. Use the links below to answer the following questions:

MATLAB scripts and functions: https://www.mathworks.com/help/matlab/learn_matlab/scripts-and-functions.html

MATLAB creating and running scripts
https://www.mathworks.com/help/matlab/matlab_prog/create-scripts.html

a) What is the difference between a script and function?

b) How do you create a new script or function in MATLAB?

c) List two ways to run a script in MATLAB

4) Follow the link to read about breakpoints in MATLAB: www.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html

Briefly explain what a breakpoint is and how to set one.

Reference no: EM131218071

Questions Cloud

Cases for a university library borrowing system : Create a set of use cases for a university library borrowing system. (Do not worry about catalogue searching, etc.) The system will record the books owned by the library and will record who has borrowed what books.
Highlight the characteristics that make a leader efficient : Select a leader, either past or present, you would like to emulate, and highlight the characteristics that make him / her an effective leader.
Component of the creating a scene view : Clipping algorithms are an important component of the creating a scene view. Explain why clipping is necessary. Choose an example of a boundary and a line and show how the endpoints of the clipped line can be calculated.
Project management framework : 1) Define what the project management framework is and explain what pieces make up the framework. What are the processes and framework? What is the purpose of having a framework?
What is the difference between a script and function : What is the difference between a script and function? How do you create a new script or function in MATLAB? List two ways to run a script in MATLAB.
Approach a bluecube kiosk : Customers should be able to approach a BlueCube kiosk and view the DVDs that are available for checkout within the device.  Upon selecting one or more DVDs, the customer can swipe his/her credit card and the DVD(s) will be delivered from the kiosk..
Discussing the pros of deploying microsoft direct : Write an email to your boss discussing the pros (or cons) of deploying Microsoft's DirectAccess instead of keeping the legacy VPN solution. Explain what you'll need to get the solution in place and what benefits it'll provide to the remote staff.
Discuss the impact of technology on the communication system : Discuss the impact of technology on the communication system. - Does technology improve or confuse the system?
What are the benefits of using nap : Describe a scenario where an organization will need to use NAP? What are the benefits of using NAP?

Reviews

Write a Review

MATLAB Programming Questions & Answers

  Compute orientation of the principal axes of cross section

Compute the orientation of the principal axes of the cross section using the eigen- value solver in MATLAB (eig) on the moment of inertia matrix J. See the CP Notes for more information on this task.

  Build a matlab birthday cake using the cylinder

Prepare for Project you should carefully read the Notes on Trajectory Formation that are available on Moddle.  As you read them, you should try out the concepts in MATLAB.

  A function of the energy e of the beams

A new particle has been discovered in a lab by colliding two beams of leptons and measuring how many particles are produced as a function of the energy E of the beams. The table below gives the results.

  Determine the specular component

Reparemeterizing each pixel point using spherical coordinates and rotation RGB color space to SUV color space in the paper

  Create a function that will determine the total resistance

Create a function that will determine the total resistance of a number of resistors that are connected in parallel. This function should accept a row vector for input,

  Implement the support vector machine algorithm

Write a program to implement the Support Vector Machine algorithm. Train an SVM classifer with data from to3 and (04 in the following way - Train your classifier with just the first patterns in 03 and aht and find the separating hyperplane and the ..

  Matlab program to compute how much money will accumulate

Write a MATLAB program to compute how much money will accumulate in 5 years in the account and in any CDs you buy. Run the program for two different savings interest rates: 4 percent and 5 percent.

  With a time step of h 01 in each case use starting values

dydt yt- yt2 1 le t le 2 y1 1approximate the solution to the above initial value problem usinga 2-step

  Explain the difference in trajectory

Write a single function that outputs the total time of flight, range of the projectile and the velocity on impact given inputs of g, the angle,

  Multimedia write the code in matlab use of publicly code

MultimediA You need to write the code yourself in Matlab Use of publically available code (e.g., from online sources) is not permitted

  Matlab code to solve for temperature and pressure variation

Write down the MATLAB code to solve for temperature and pressure variation throughout the expansion process and to evaluate work and heat produced in processes for variable values of n.

  Develop a well-structured function

Develop a well-structured function to compute v as a function of t. Then use this function to generate a table of v versus t for t = -5 to 50 at increments of 0.5.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd