MATLAB. Creating a function involving interpolation.

In summary, the function 'lookup' takes in a temperature value as input and uses the 'interp1' function to find the corresponding value in the provided table. If the input temperature is greater than 10, the function will return the interpolated value. The table contains temperature and corresponding values, and the code uses the 'interp1' function to find the value at the input temperature.
  • #1
thst1003
18
0
I have attached a pdf of the complete problem. I have been trying this for a few days and still can't figure it out. The book provided with this course does not give good information on this topic nor did the class lecture.

y1 = interp1(x,y,x1)


This is what I have so far:

function y1 = lookup(getTemp)

table = [99.63, 100, 120, 160, 200, 240, 280, 320, 360, 400, 440, 500
1.694, 1.696, 1.793, 1.984, 2.172, 2.359, 2.546, 2.732, 2.917, 3.103, 3.288, 3.565];

if getTemp > 10
y1 = interp1(table, getTemp);
end

Any help would be greatly appreciated. I am really struggling.
 

Attachments

  • Assignment 12.pdf
    276.6 KB · Views: 284
Physics news on Phys.org
  • #2
The code should be: function y1 = lookup(getTemp)table = [99.63, 100, 120, 160, 200, 240, 280, 320, 360, 400, 440, 500; 1.694, 1.696, 1.793, 1.984, 2.172, 2.359, 2.546, 2.732, 2.917, 3.103, 3.288, 3.565];x = table(1,:);y = table(2,:);if getTemp > 10 x1 = getTemp; y1 = interp1(x, y, x1);end
 

FAQ: MATLAB. Creating a function involving interpolation.

What is MATLAB?

MATLAB is a programming language and interactive environment commonly used in scientific and engineering fields. It allows users to perform complex mathematical calculations, create visualizations, and analyze data.

How do I create a function in MATLAB?

To create a function in MATLAB, you can use the "function" keyword followed by the function name and input arguments. Then, within the function, you can define the code to be executed and the output of the function.

What is interpolation?

Interpolation is a mathematical method used to estimate the values between known data points. It involves finding a function or equation that closely fits the given data points, allowing for the estimation of values at points that fall in between.

How can I incorporate interpolation into a MATLAB function?

To incorporate interpolation into a MATLAB function, you can use built-in interpolation functions such as "interp1" or "interp2". These functions allow you to specify the type of interpolation to be used and the data points to be interpolated.

What are the benefits of using MATLAB for creating functions involving interpolation?

MATLAB offers a variety of tools and functions specifically designed for data interpolation, making it a powerful and efficient tool for creating functions involving interpolation. Additionally, the interactive environment of MATLAB allows for easy testing and debugging of the function, ensuring accuracy and reliability of the results.

Back
Top