Question

Using MATLAB Linear Interpolation: The following equation illustrates how to calculate an output for any input,...

Using MATLAB Linear Interpolation:

The following equation illustrates how to calculate an output for any input, using linear interpolation. The input must be within the bounds of the data set. The constants come from the data set; they are the nearest data points that bound the original input.

(constants from data set--> y1, x1, y2)

(output--> y) (input--> x)

Create a MATLAB function file that calculates the linearly interpolated y-value (output) provided an x-value (input). The function should linearly interpolate to find y given any x using the air velocity and thermal resistance data below. You are required to use a for-loop: Use a for loop inside this function file that loops through the rows of the data to determines which two rows of the data an input falls between. The row that is the lower bound will become the x1 and y1 values; the row that is the upper bound will become x2 and y2.

Calculate y given x, x1, y1, x2, and y2.

Test the code by calling this user-defined function inside the for loop of a script for values from 0 to 1700 (air velocity) and plotting the results.

Example:

x= 480

x1=400 (Lower Bound)

x2=600 (Upper Bound)

y1=113.6, y2=93.1

Resulting value of y: 105.4

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

%linear interpolate . m function y=linear interpolate (air velocity, thermal resist, x) x1-0; x2-0; y1-0: y2-0; k=0 ; %lowerend end sdisplay y value y ylt x-x1)((y2-y1)/ (x2-x1))) endSmain.m x-480 air velocity I0,200,400,600,800,1000,1200,1400,1600,1800] thermal_resist-[373.0,156.1,113.6,93.1,81.5,73.7,67.2

output:

У 105. 4θ

350 300 订)() 250 200 150 1 500 50 1000 1500 2000

copyable code:

%linear_interpolate.m

function y=linear_interpolate(air_velocity,thermal_resist,x)

x1=0;

x2=0;

y1=0;

y2=0;

k=0;

%lower and upper bound

for k1=1:length(air_velocity)

if x<air_velocity(k1)

x2=air_velocity(k1);

x1=air_velocity(k1-1);

y2=thermal_resist(k1);

y1=thermal_resist(k1-1);

end

end

%display y value

y=y1+ ((x-x1)*((y2-y1)/(x2-x1)));

end

%main.m

x=480;

air_velocity=[0,200,400,600,800,1000,1200,1400,1600,1800];

thermal_resist=[373.0,156.1,113.6,93.1,81.5,73.7,67.2,62.4,58.3,55.0];

y=linear_interpolate(air_velocity,thermal_resist,x)

%plot

xlabel('Air Velocity');

ylabel('Thermal Resistance');

plot(air_velocity,thermal_resist);

Add a comment
Know the answer?
Add Answer to:
Using MATLAB Linear Interpolation: The following equation illustrates how to calculate an output for any input,...
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
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