Find five correct decimals of temp at x

2 次查看(过去 30 天)
If I have a plot, how can I find the temperature at x=1 with five accurate decimals? It must be a way in which I have compared and can trust that the decimals are in fact accurate.
For example, say this is my code:
clear all, close all, clc
L=3.4;
N=100;
T0=300;
Tslut=410;
h=L/N;
x=linspace(0,L,N+1);
x=x.';
fk=@(x)2+x/7;
fQ=@(x)260*exp(-(x-L/2)^2);
A=zeros(N+1);
b=zeros(N+1,1);
A(1,1) = 1.0;
b(1) = T0;
for i=2:N
xp=x(i);
xhl=xp-h/2;
xhr=xp+h/2;
A(i,i-1) = -fk(xhl);
A(i,i) = (fk(xhl)+fk(xhr));
A(i,i+1) = -fk(xhr);
b(i) = fQ(xp)*h^2;
end
A(N+1,N+1) = 1.0;
b(N+1) = Tslut;
T=A\b;
plot(x,T)
All help is appreciated!

回答(1 个)

Alan Stevens
Alan Stevens 2020-10-10
How about using
T1 = interp1(x,T,1);
Use a finer mesh of x values if the result isn't satisfactory.
  1 个评论
Katara So
Katara So 2020-10-10
I thought about using that however our professor said that we have to show what makes us trust the five decimals. I don't really know how interp1 works and therefore I don't know if the answer given is trustworthy. Would be a good enough way of checking the decimals?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by