What is the difference between a script and function

Assignment Help MATLAB Programming
Reference no: EM13802272

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?

Reference no: EM13802272

Questions Cloud

Write a paper about article body ritual among the nacirema : Write a Reflection Response paper about the article "Body Ritual Among the Nacirema" by Horace Miner.
What was the input of interest groups : What was the input of interest groups
Increasingly competitive environment : As organizations experience greater pressure to ensure profitability in an increasingly competitive environment, this may potentially cause decision makers to compromise their ideals in order to accomplish their goals.
Describe the rfp preparation process : Describe the RFP preparation process. What are some of the key components and why are these important? We've talked about different kinds of neutral or routine messages.
What is the difference between a script and function : Learn how to use various MATLAB built-in functions, What is the difference between a script and function? How do you create a new script or function in MATLAB
Bureaucratic and clan control mechanisms : Using the University online library resources and the Internet, research bureaucratic and clan control mechanisms and then complete the following:
Teamwork and project management : Review the "Meeting" section in your text Teamwork and Project Management (p. 103-105). In a two- to three-page paper (not including the title and reference pages), describe the topic of your final project including the types of team members neede..
Describe your current philosophy of assessment : Write a 2-3 page paper describing your current philosophy of assessment. Include the following: In your own words, what is the purpose of assessment?
What is the relation expressing thermal equilibrium : What is the relation expressing thermal equilibrium between systems 1 and 2 - what are the three functions which are equal to one another at thermal equilibrium and each of which is equal to T, empiric temperature (on some scale).

Reviews

Write a Review

MATLAB Programming Questions & Answers

  Using matlab and for loops

Using MATLAB and for loops, provide an animation that follows the below steps: Start with a square at the origin with each side being 5 units long. Imagine someone kicked the box and animate it moving on a projectile motion trajectory. Hint: look at ..

  Using dimensional analysis nondimensionalize the period t

the period of a pendulum t is assumed correctly or incorrectly to depend on the mass m the length of the pendulum l the

  Program should be able to handle collisions

Write a program that, given a list of 5 social security numbers, finds the memory locations assigned by the hashing function h(k) = k mod 55 to store customer records. program should be able to handle collisions.

  Write a user defined function

Write a user defined function FindFrequency which inputs are a time and a wave elevation vector and output the approximated wave frequency (fappr=FindFrequency(t,eta)).

  Considered to equal when the result of one array subtract

Two arrays are considered to be equal when the result of one array subtracted from the other is an array of zeros. In the script file, create the MATLAB commands to prove the following relationships (use arrays that you makeup yourself)

  Develop a simulation program

Develop a simulation program

  Write a script that will loop through values of n

Write a script that will loop through values of n until the difference between the approximation and the actual value is less than 0.0001.

  Implement newtons method in matlab

Implement the secant method in Matlab and Implement Newtons method in Matlab

  Stepper motor driven xy table

Stepper Motor Driven XY Table - Use Matlab and Labjack to acquire digital inputs from limit switches and use Matlab to analyze acquired data

  Evaluate the main effects and the interaction

Do the results indicate that self-esteem is significantly higher on average for males at significance level of 0.01 - Evaluate the main effects and the interaction at a level of significance of 0.05.

  It''s a mechanical engineering project proposal

It's a mechanical engineering project proposal. the program that we using is called "Mat lab". Here are the rules for the project proposal.

  Fit the exponential function to the relaxation data

Fit the exponential function to the relaxation data and report the filename as well as the A, tau and B values and run all 3 functions in sequence to analyze ALL data

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