Question

In: Computer Science

9.) Write a MATLAB script that will read the Pressure and Temperature columns from the provided...

9.) Write a MATLAB script that will read the Pressure and Temperature columns from the provided Excel file. Use a loop to calculate the linear best fit line for the data. You may only use the built-in functions sum, size, and length. Plot both the individual data points (red) and the fit line (blue) on the same graph. Include a title and axes labels.

Solutions

Expert Solution

clc
clear all
close all
format long
P=[1,5,10,15,20:5:50];
T=[300,315,330,345,360,375,390,405,420,435,450];
Sx=0;
Sx2=0;
Sy=0;
n=length(P);
Sxy=0;
for i=1:n
Sx=Sx+P(i);
Sy=Sy+T(i);
Sxy=Sxy+P(i)*T(i);
Sx2=Sx2+P(i)^2;
end
a=(Sy*Sx2-Sx*Sxy)/(n*Sx2-Sx^2);
b=(n*Sxy-Sx*Sy)/(n*Sx2-Sx^2);
fprintf('Best fit line is T=%f*x+%f\n',b,a);
C=[b,a];
xx=0:0.01:50;
plot(xx,polyval(C,xx),'b',P,T,'or');
xlabel('X');
xlabel('Y');
title('Plot of f and fit');


Related Solutions

3. Write a Matlab script that describes the dynamics of Pressure and Flow in the systemic...
3. Write a Matlab script that describes the dynamics of Pressure and Flow in the systemic arteries and Left Ventricle. Assume that : 1) Pressure in the Left atrium (PLA) and in the Systemic Veins (Psv) remain constant. 2) A time dependent LV compliance 3) Opening/Closing of the heart valves instantaneously with the direction of flow (i.e. valves are at an open or closed states. Use parameter values from the handout.
MATLAB: Write as a script in the editor window of matlab. Quadratic roots. Write a program,...
MATLAB: Write as a script in the editor window of matlab. Quadratic roots. Write a program, quadroots.m, for finding the roots of the second- order polynomial ax2 + bx + c. Use the quadratic equation. The inputs are the coefficients a,b, and c and the outputs are z1 and z2. The program should produce (exactly) the following output in the Command window when run with (a, b, c) = (1, 2, −3):
USE R STUDIO. Consider the pressure data frame. There are two columns: temperature and pressure: •...
USE R STUDIO. Consider the pressure data frame. There are two columns: temperature and pressure: • Construct a scatterplot with pressure on the vertical axis and temperature on the horizontal axis. • The graph of the following function passes through the plotted points reasonably well: y = (0.168 + 0.007 ∗ x) ^(20/3). Recall that the differences between the pressure values predicted by the curve (i.e. y) and the observed pressure values (i.e. the pressure values obtained from the data...
Write The MATLAB SCRIPT for: An open-top box is constructed from a rectangular piece of sheet...
Write The MATLAB SCRIPT for: An open-top box is constructed from a rectangular piece of sheet metal measuring 10 by 16 inches. Square of what size (accurate to 10-9 inch) should be cut from the corners if the volume of the box is to be 100 cubic inches? Notes: to roughly estimate the locations of the roots of the equation and then approximate the roots to this equation using Newton Iteration method. Please don't give me the Matlab Commands for...
Write a script to display the following patterns on the screen. Number of rows and columns...
Write a script to display the following patterns on the screen. Number of rows and columns are taken from the command arguments; if they are missing, set default to 3 (rows) and 4 (columns). Hint: you will use a nested loop. **** **** **** a) Display the source code in an editor (#4-11) b) Execute your script in the terminal, and display the command and the result (#4-12)
write a matlab script for double mass spring system with animation.
write a matlab script for double mass spring system with animation.
Part A: Write a MATLAB script to find the volume of the cylinder in gallons, as...
Part A: Write a MATLAB script to find the volume of the cylinder in gallons, as well as the tank dimensions in feet. Assume that the initial measurements are 7 meters in diameter and 11 meters tall. Display your final answers to the screen using disp and a statement without a semicolon, e.g. write the following into your script disp(‘The capacity in U.S. gallons is:’), capacity, where capacity is a variable that you defined in preceding calculations. Part B: In...
(MATLAB) Write a script that would create a 3x5 matrix of random integers and write this...
(MATLAB) Write a script that would create a 3x5 matrix of random integers and write this new matrix to a file called “Assignment3_Question5.dat”.
Program in Bash: Write a program using bash script that can read a file from the...
Program in Bash: Write a program using bash script that can read a file from the same directory, sort the nonrepeating integers from 0-9 from smallest to largest, and output the results on the same line. Do not use the sort function.
Program in Bash: Write a program using bash script that can read a file from the...
Program in Bash: Write a program using bash script that can read a file from the same directory, sort the nonrepeating integers from 0-9 from smallest to largest, and output the results on the same line. Do not use the sort function.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT