Please what did i do wrong here..using interp2

i was given a table of y\x and the given values of the corresponding temperatures, and i was told to find the estimate of the temperature at (1.2,0.7). i did my code but it did not seem to be right when i ran it .here is the code:
y=0.0:0.5:2.0;
x=0.0:0.5:2.5;
T= [0.00 5.00 10.00 15.00 20.00;
5.00 7.51 10.00 12.51 15.00;
10.00 10.05 10.00 9.95 10.00;
15.00 12.70 10.00 7.32 5.00;
20.00 15.67 10.00 4.33 0.00;
25.00 20.00 10.00 0.00 -5.00;];
Tn= interp2(x,y,T,1.2,0.7)

Respuestas (2)

Image Analyst
Image Analyst el 11 de Abr. de 2015
All too common of a beginners mistake. You thought x,y = row,column. It's NOT. In other words, you swapped x and y. Remember the rows = y, not x like you had them, and the columns = x, not y like you had. So x,y = columns, rows, NOT rows, columns. Here is corrected code:
x=0.0:0.5:2.0;
y=0.0:0.5:2.5;
T= [0.00 5.00 10.00 15.00 20.00;
5.00 7.51 10.00 12.51 15.00;
10.00 10.05 10.00 9.95 10.00;
15.00 12.70 10.00 7.32 5.00;
20.00 15.67 10.00 4.33 0.00;
25.00 20.00 10.00 0.00 -5.00;];
whos y
whos x
size(T)
Tn= interp2(x,y,T,1.2,0.7)

5 comentarios

ggeneral
ggeneral el 11 de Abr. de 2015
but the question says y is columns. see question 2
Image Analyst
Image Analyst el 11 de Abr. de 2015
No it doesn't. x is columns, y is rows. Look again. Also, your T is wrong - doesn't match your textbook. It seems to be transposed or something.
ggeneral
ggeneral el 11 de Abr. de 2015
i didnt need to use the semi-columns? when i ran it the table appeared like that on matlab.. im confused
ggeneral
ggeneral el 11 de Abr. de 2015
ok i figured it out...thank you..im really slow
Image Analyst
Image Analyst el 11 de Abr. de 2015
They show a 5 row by 6 column table. You have a 6 row by 5 column table. And, no, semicolons are not required when writing out a table on multiple lines.

Iniciar sesión para comentar.

Star Strider
Star Strider el 11 de Abr. de 2015
@George — As I read Problem 2, you transposed the table. It’s supposed to be (5x6). Yours is (6x5). Transpose ‘T’ (use the (') transpose operator to avoid retyping it) and your code should work.
y=0.0:0.5:2.0;
x=0.0:0.5:2.5;
T= [0.00 5.00 10.00 15.00 20.00;
5.00 7.51 10.00 12.51 15.00;
10.00 10.05 10.00 9.95 10.00;
15.00 12.70 10.00 7.32 5.00;
20.00 15.67 10.00 4.33 0.00;
25.00 20.00 10.00 0.00 -5.00;];
T = T';
Tn= interp2(x,y,T,1.2,0.7)
produces:
Tn =
10.6660

Categorías

Preguntada:

el 11 de Abr. de 2015

Respondida:

el 11 de Abr. de 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by