 # Matlab Questions

## Question

Show transcribed text

## Transcribed Text

General Instructions For Problems #1, #2, #3, #4-part1 (Paper write-ups): • Unless otherwise specified, you must show your equations and calculations to get full credit. • For significant figures, do all of the calculations first and then round off at the very end. • Solutions should be either hand-written on engineering paper or printed out using a computer. • Follow the presentation format discussed in the “Problem Solving” lecture. o You may omit the Discussion. • Either draw a double underline beneath or box the final answers you want graded. • Submit your paper solutions to the Instructor at the beginning of class. For Problems #4-part2, #5, #6, #7, #8 (MATLAB script files): • Save each problem in a separate MATLAB file. • Insert the following information in a comment block at the top of each script: o Name (last, first) o Course #, Homework #, and Problem # o Date For function files, embed this block within the Help Text area. • Document your solutions with appropriate comments as needed. Problem #1 The circuit on the left in Figure 1 is a basic voltage divider. The circuit on the right is a representation of the input resistance of a voltmeter, which is an instrument designed to measure voltages via its external probes (wires). Assume component values are known to three (3) significant figures. Requirements – Part 1 In this part, the voltmeter is not connected at all to the voltage divider. a) Suppose you wanted to produce a voltage of 3.00 V across resistor R2 (i.e., VR2 = 3.00 V). Use the voltage divider equation to find the value (in kΩ) of R1 that is needed. b) Using your design value for R1, verify that the voltage drop across R2 is 3.00 V. Requirements – Part 2 In this part, the voltmeter probe x is connected to terminal b on the voltage divider, and probe y is connected to terminal c. c) Suppose the voltmeter has input resistance Rinput = 100. kΩ. What will be the value (in V) of VR2 that the voltmeter measures and displays? d) Suppose you replace the voltmeter with a different model that has Rinput = 1.00 MΩ. What will be the value (in V) of VR2 that the voltmeter measures and displays? e) Using the results from Parts (c) and (d), what conclusion can you draw about which voltmeter is better? Explain the behavior you observed. R2 = 150 kΩ VR2 R1 b VS = 9 V + − a c Figure 1 I Rinput Internal model of the input stage of a voltmeter Voltmeter probes x y Problem #2 Assume component values are known to three (3) significant figures. Requirements – Part 1 a) Without using the mesh current method, find the branch current (in A) through R3. b) Without using the mesh current method, find the voltage drop (in V) across R4. Hint: Apply your knowledge of equivalent resistance to simplify the circuit as needed. Requirements – Part 2 c) Apply the mesh current method to write the system of linear equations in matrix form (i.e., Ax = b). Label your mesh currents I1 and I2 (from left to right). d) Calculate the values (in A) of the mesh currents I1 and I2. e) Using the results from Part (d), find the branch current (in A) through R3. Show the equation you used. R1 = 3 Ω VS = 6 V + – R2 = 2 Ω R3 = 4 Ω R6 = 1 Ω R4 = 3 Ω Figure 2 R5 = 2 Ω Problem #3 Assume component values are known to three (3) significant figures. Requirements a) Apply the mesh current method to write the system of linear equations in matrix form (i.e., Ax = b). Label your mesh currents I1 and I2 (from left to right). b) Calculate the values (in A) of the mesh currents I1 and I2. c) Calculate the amount of power (in W) dissipated by R2. d) Find the power (in W) generated by voltage source V1. R1 = 3 Ω V1 = 6 V + – R2 = 4 Ω R3 = 1 Ω Figure 3 + – V2 = 2 V Problem #4 Assume component values are known to three (3) significant figures. Requirements – Part 1 a) Using the given names and directions, apply the mesh current method to write the system of linear equations in matrix form (i.e., Ax = b). b) Calculate the values (in A) of the mesh currents I1, I2, I3, and I4. Note: You can use your MATLAB script from Part 2 to accomplish this task. Requirements – Part 2 Using the equations you developed in Part 1, write a MATLAB script to compute and display (in A) the mesh currents I1, I2, I3, and I4. • Save your script file using this name: hw5p4.m R2 V2 + – I2 I3 R3 R4 V1 = 5 V V2 = 9 V V3 = 2 V R1 = 5 Ω R2 = 3 Ω R3 = 2 Ω R4 = 7 Ω R5 = 1 Ω R6 = 4 Ω R7 = 6 Ω R8 = 8 Ω R1 V1 – + I1 V3 R7 I4 + – R8 R5 Figure 3.1 R6 Problem #5 Your job is to paint the exterior surface of some manufactured spheres with paint. The amount you charge to the customer depends on the amount of surface area and the cost of the paint. Requirements Write a MATLAB function named paint that satisfies the following: • Accepts these two input arguments: o Radius of the sphere (in inches) o Price of the paint (in \$ per ft2 ) • Returns this output argument: o Total cost of the paint job (in \$) • Includes an H1 help line • The function itself should not prompt the user for input or display any output! • Save your function file using this name: paint.m Sample Run (at the Command Window) >> help paint paint(R, P) calculates the cost of painting a sphere. R = radius of sphere (in inches) P = price of the paint (in \$/ft^2) Returns the total cost (in \$) >> paint(3.5, 0.75) ans = 0.8018 >> sp_cost = paint(12, 1.25); >> disp(sp_cost) 15.7100 Problem #6 The paint function you wrote in Problem #5 is nice, but you think it is still too much work to manually pass input arguments to it and then manually display the calculated cost. So, you decide to write a separate script to invoke it. In fact, you want to create an extra function to handle prompting the user for input values and call if from the script as well. Requirements Write a new MATLAB function named ask_user that satisfies the following: • Has no input arguments. • Prompts the user to enter both the radius and price. Use the standard input function. • Returns these two output arguments: o Radius of the sphere o Price of the paint • Includes an H1 help line • Save your function file using this name: ask_user.m Write a MATLAB script that satisfies the following: • Calls the ask_user function to get the required data. • Passes the returned data to the paint function. • Nicely displays the calculated cost returned by paint. • Save your script using this name: hw5p6.m Sample Run (at the Command Window) Enter the sphere's radius (inches): 12 Enter the paint's price (\$/ft^2) : 1.25 Radius = 12.00 inches Price = \$1.25/ft^2 Cost of painting the sphere is \$15.71. Problem #7 The inverse sine function (asin) and inverse cosine function (acos) are valid only for inputs between –1 and +1, because both the sine and the cosine have values only between –1 and +1. MATLAB interprets the result of asin or acos for a value outside the range as a complex number. For example, we might have acos(-2) ans = 3.1416 – 1.3170i which is a questionable mathematical result for our purposes. Requirements Write a MATLAB function named my_asin that satisfies the following: • Accepts a single value x. • Checks if x is within the legal range –1 and +1 (inclusive at both endpoints) • Displays an error message if x is outside the legal range. Otherwise, returns the asin value. • Includes an H1 help line • Save your function file using this name: my_asin.m Sample Run (at the Command Window) >> sin(0.5) ans = 0.4794 >> asin(0.4794) ans = 0.5000 >> asin(3) ans = 1.5708 - 1.7627i >> my_asin(0.4794) ans = 0.5000 >> my_asin(3) Error: allowed range is -1 <= x <= +1 Problem #8 You need to figure out the area of some basic 2-dimensional shapes, so you decide to write a script to make your work easier. Requirements – Part 1 Write a a MATLAB script that meets these specifications: • Print the following list to the command window: circle, triangle, rectangle, and trapezoid • Prompt the user to choose one of these shapes (numeric code 1, 2, 3, 4, respectively). • Use either a nested if-else statement or an if-elseif statement to handle the choice. • If the user enters an invalid choice, print an error message and quit the script. • Prompt the user for the dimensional values that are appropriate for the chosen shape. You may assume unitless quantities. • Print the computed area to two decimal places. • Do not use the menu or inputdlg functions for this part. • Save your script using this name: area1.m r h b a b b a h Sample Run (at the Command Window) >> area1 List of shapes: 1. Circle 2. Triangle 3. Rectangle 4. Trapezoid Please choose one: 1 Enter radius r: 12.5 The area is 490.87 square units. >> area1 List of shapes: 1. Circle 2. Triangle 3. Rectangle 4. Trapezoid Please choose one: 3 Enter length a: 15 Enter width b: 6.25 The area is 93.75 square units. >> area1 List of shapes: 1. Circle 2. Triangle 3. Rectangle 4. Trapezoid Please choose one: 4 Enter upper base a: 3 Enter lower base b: 7 Enter height h: 5 The area is 25.00 square units. >> area1 List of shapes: 1. Circle 2. Triangle 3. Rectangle 4. Trapezoid Please choose one: 7 Error: Invalid choice Requirements – Part 2 Write another MATLAB script that meets these specifications: • Use the menu function to display the circle, triangle, rectangle, and trapezoid options. • Use a switch statement to handle the choice. • Use the inputdlg function to ask the user for the chosen shape’s dimensions. • Use the msg function to show the computed area to two decimal places. Hint: The sprintf function could be useful here. • If the user canceled early, use the msg function to display a message that says the area calculation was canceled. • Save your script using this name: area2.m Sample Run (at the Command Window)

## Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

function [angle] = myasin(sideRatio)
%sideRatio returns the value of asin when the input is appropriate
%   sideRatio = value between -1 and 1
% An error message will be displayed if input is not between -1 and 1
%Returns the asin value
if sideRatio<=1 && sideRatio>=-1
angle=asin(sideRatio);
else
fprintf('Error: Allowed range is -1 <= sideRatio <= +1\n')
end...
\$23.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

### Find A Tutor

View available MATLAB for Engineering Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

• 1
• 2
• 3
Live Chats