QuestionQuestion

Transcribed TextTranscribed Text

Example # 1 Background Material Resistors can be made out of many different materials and the value of their resistance is expressed in Ohms (). The value of resistance can be expressed using this formula: L R A where P is resistivity (units Q-cm), L is resistor length (in cm) and A is cross-sectional area (in cm"). Required Work For the following problem, assume all numbers have units as expressed above. You can also assume that material resistivity is set to p- 10 Q-cm. a) Write a function named resist that accepts the resistivity p. length L. and area A as input arguments and returns as output arguments the value of resistance and error variable. The function should work when p. L and A are scalar and when they are vectors. The function itself should not prompt the user for input, and it should not print any values. The function should check that all input arguments are positive in which case error variable should be set to logical false or o. If any of the input arguments are negative or equal to zero the error variable should be set to logical true or 1. b) Write a script that satisfies these criteria: Prompt the user for the length L of one or more resistors. Store them in a vector. Prompt the user for the cross-sectional area A of one or more resistors. Store them in vector. Invoke the resist function and pass the p. L and A vectors to it. If the value of the error variable is "true" display a message "Your data is negative or equal to zero" If the value of the error variable is "false" then print out the values of p. L. A and the calculated resistance using a for loop (optional practice: use while loop instead). If you computer is Micosoft Windows based store your filc(s) in C: \temp- Sample test data for verifying your results: Suppose the user enters 10, 30, and 80 for the lengthsand 1, 2,and 2.5 for the areas- Your output should look similar to the following table Note You are not required to print out the text labels above cach column- Enter length values [10 30 80] Enter area values [1 2 2.5] 10.00 10.00 1.00 100.00 10.00 30.00 2.00 150.00 10.00 80.00 2.50 320.00 Example 2 Background Material Various rates of discharge of a pump Werc measured and the corresponding power required for cach discharge was recorded. as given below. Table: Pump Power required to produce Discharge Discharge, Q(L/s) Power, P(kW) 5 38 10 53 15 57 20 67 25 72 30 88 40 105 50 125 60 129 Required Work a) Write a function slope that calculates the slope m of the least squares linear regression function (see below). It should have two input arguments: x and v. where x is independent variable and yis dependent variable. Both x and y are vectors. Use this equation to calculate the slope of the linear regression function Summation is over the entire vector and n is the number of data points. Use for loop(s) to accomplish summations. (optional practice: use while loop instead.) m b) Write a script that satisfies these criteria: Set uptwo vectors: Q to store discharge values, and P to store power values, as given in the table. Prompt the user for the type of plot he/she would like. Options are: lin-lin, lin-log, log-lin and og-log. Store user's choice in a variable. Plot P vs. Q using the plot type selected by user. Properly label the axes and provide a good title. Call function slope and pass 2and P as input arguments. Use disp or fprintf to display the slope returned by function slope.

Solution PreviewSolution 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 m = slope(X,Y)
    n=length(X);
    sumX=0;
    sumY=0;
    sumXsquare=0;
    sumYsquare=0;
    sumProductXY=0;
   
    for i=1:n
       sumX=sumX+X(i);%sum of x values
       sumY=sumY+Y(i);%sum of y values
       sumXsquare=sumXsquare+(X(i))^2;%sum of the square of each x value
       sumYsquare=sumYsquare+(Y(i))^2;%sum of the square of each y value...
$13.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.

Decision:
Upload a file
Continue without uploading

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