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 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...

This is only a preview of the solution. Please use the purchase button to see the entire solution

$13.00 for this solution

Sorry, there was an error processing your request

Sorry, there was a problem with your payment. Please try again or try another payment method.

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

Please let us know the date by which you need help from your tutor or the date and time you wish to have an online tutoring session.

Request Speed

Normal response time: Our most experienced, most successful tutors are provided for maximum expertise and reliability.

Fast response time: Used only for emergencies when speed is the single most important factor.

Why do we ask for this?

We require your email address so that we can send you an email alert when the tutor responds to your message.

We respect your privacy. Your email address will not be used for any other purpose.
You may read our privacy policy for more info.

Please use a personal email address

Please use an email address that does not end in .edu.

This is not a free service

You will get a negotiable price quote with no obligation.

Homework Due Date

Please let us know the date by which you need help from your tutor or the date and time you wish to have an online tutoring session.

Request Speed

Normal response time: Our most experienced, most successful tutors are provided for maximum expertise and reliability.

Fast response time: Used only for emergencies when speed is the single most important factor.

Why do we ask for this?

We require your email address so that we can send you an email alert when the tutor responds to your message.

We respect your privacy. Your email address will not be used for any other purpose.
You may read our privacy policy for more info.

This is not a free service

You will get a negotiable price quote with no obligation.

Homework Library

Warning: If you try using the HL in an unethical manner, expect to fail your class. All HL items are old, recycled materials and are therefore not original. We intend them to be used only for the purpose of studying and learning.