Question

MAT LAB: write a program that can choose from an assortment of calculations and perform the...

MAT LAB:

write a program that can choose from an assortment of calculations and perform the desired physics calculation in order to streamline the design and modelling process.

Your function should take three inputs in the following order: var1 – The first number in the calculation you want to perform. var2 – The second number in the calculation you want to perform var3 – The third number in the calculation you want to perform indicator . A variable, that has a data type of your choice , that the user will use to determine which operation to perform. You should note in a comment how you are implementing the indicator variable.

Your function should have one output, result. Your function should be able to perform the following operations, and should assume SI units for each input:

Distance. Given var1 as a 1-dimensional acceleration, and var2 as 1-dimensional velocity, and var3 as time, determine result via the formula:

???????? = ???????? ∗ ????* 1/2 ???????????? ∗ ????^2

Work. Given var1 as a force, var2 as a distance an object moved, and var3 as the angle between the force and the direction of movement (in radians), determine result via the formula:

???? = ????? ∗ ???????? ∗ cos(?????)

Falling object velocity: Given var1 as an initial speed and var2 as an amount of time, and var3 as the force of gravity acting upon the object, calculate the result via the formula:

????????????? = ??????????????? + ? ∗ ????

Torque. Given a var1 as a force acting upon an object with a fixed axis of rotation, var2 as a distance away from the axis of rotation, and var3 as the angle of the force with respect to the parallel along which the distance was measured, calculate the result via the formula:

?????? = ????? ∗ ???????? ∗ sin(?????)

Note that every time this function is called, it should only perform one of these calculations. However, the user should be able to choose from any of the calculations with each call using the indicator input. If a user calls your function with an indicator value that is not associated with anything, please return a string with a message indicating this as your output instead of the result of a calculation.

Thanks!

It would be great if this was written with: if else/while/for statements (just bc that is what we have covered in class!)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother function file are not meant to be run directly they are either run through the command window or some script and should be saved with the same name mentioned below. In case of any queries brother just comment in box I would be very happy to assist all your queries.  

=========================================

Save file as calculateVar.m

========================================

function y=calculateVar(var1,var2,var3,ind)
y=0;
if(ind==1)
y=var2*var3+0.5*var1*var3*var3;
elseif(ind==2)
y=var1*var2*cos(var3);
elseif(ind==3)
y=var1+var2*var3;
elseif(ind==4)
y=var1*var2*sin(var3);
else
y='It is not
valid indicator';
end
end

========================================

Executable command to test

========================================

y=calculateVar(5,8,3,3)

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
MAT LAB: write a program that can choose from an assortment of calculations and perform the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using MATLAB. As an engineer working on designing and modelling a new drone product, you are...

    Using MATLAB. As an engineer working on designing and modelling a new drone product, you are doing a lot of different physics calculations. Your boss wants to write a program that can choose from an assortment of calculations and perform the desired physics calculation in order to streamline the design and modelling process. For this project you will write a function called PhysicsCalc. inputs Your function should take three inputs in the following order: var1–The first number in the calculation...

  • Easy Javascript questions You can use window.history to retrieve the history object. Using the history object, what methods can you call to navigate backwards and forward to web pages that have been...

    Easy Javascript questions You can use window.history to retrieve the history object. Using the history object, what methods can you call to navigate backwards and forward to web pages that have been visited recently? The answer is not in the book. See https://developer.mozilla.org/en-US/docs/Web/API/History. Think about the situation where the alert message displays “your reply was false.” Describe the type of person who would generate that output—someone who always tells the truth, someone who always lies, or some other type of...

  • Using C programming Description: You have been tasked to design an application for an engineering...

    Using C programming Description: You have been tasked to design an application for an engineering firm to measure the performance of their vehicle designs. The user, an engineer will enter data into your program when prompted and will perform the required calculation and output the answer. The formula used for this project calculates the distance an object will cover in meters given an initial velocity, a rate of acceleration and a time of acceleration or travel. 1. Your program must...

  • (50 pts) Write a program that asks user an arithmetic operator('+','−','∗' or '/') and two operands...

    (50 pts) Write a program that asks user an arithmetic operator('+','−','∗' or '/') and two operands and perform the corresponding calculation on the operands. Specific requirements: (1) Your main function accepts inputs and display calculation result. (2) Write four functions to perform the four calculations. Call these functions in your main function. (3) Repeatedly asks for inputs, calculate and display result until user input nonnumeric value for operands. Hint: you can put getchar() right after scanf() to get rid of...

  • Write a program that calculates the average of a stream of non-negative numbers. The user can...

    Write a program that calculates the average of a stream of non-negative numbers. The user can enter as many non-negative numbers as they want, and they will indicate that they are finished by entering a negative number. For this program, zero counts as a number that goes into the average. Of course, the negative number should not be part of the average (and, for this program, the average of 0 numbers is 0). You must use a method to read...

  • Problem: Write a program to calculate the force of gravitational attraction between two objects of known...

    Problem: Write a program to calculate the force of gravitational attraction between two objects of known mass at a known distance. Use the formula developed by Isaac Newton known as Law of Universal Gravitation. F G*m *m2/d2 Where F (Force of gravity) is expressed in Newtons (N), mi and m2 (masses of the objects) are expressed in kilograms (kgs) and d (distance from the center of one object to the center of the other) is expressed in meters (m) and...

  • IN MATLAB Write a MATLAB function that can be used by a user to perform polynomial...

    IN MATLAB Write a MATLAB function that can be used by a user to perform polynomial interpolation using Lagrange Interpolation Method on a set of data. You should name your function as YourInitials_Lagrange_interpolation. 1. FUNCTION INPUT: . The input data pairs x and f(x) should be expressed as vectors and are used to construct the interpolation polynomials The interpolating data points/value The order of interpolating polynomials to be used. For this project you code should handle first order, second order...

  • with the correct answer please 5. Write a program in C++ that will perform the operation...

    with the correct answer please 5. Write a program in C++ that will perform the operation of a simple CALCULATOR. But its output will be as shown in the output Screen-short. Three(3) Marks Guideline for developing the application. Input Output 1. Start program with asking The output will be question whether user is willing 1. The chosen Operator to continue or not. 2. Calculated result 2. If answer is Yes, Like:- System will ask for c\Users\Alamgir Documents\Visual Studio 2008 Proje....

  • Description Create an object-oriented program that uses inheritance to perform calculations on a rectangle or a...

    Description Create an object-oriented program that uses inheritance to perform calculations on a rectangle or a square. Sample Output (Your output should be similar to the text in the following box) Rectangle Calculator Rectangle or square? (r/s): r Height: 5 Width: 10 Perimeter: 30 Area: 50 Continue? (y/n): y Rectangle or square? (r/s): s Length: 5 Perimeter: 20 Area: 25 Continue? (y/n): n Thank you for using my app Specifications Use a Rectangle class that provides attributes to store the...

  • Write a menu based program implementing the following functions: (0) Write a function called displayMenu that...

    Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT