Hello, I have a code for determining a temperatur after a distance form a start temperature. In the code, there is a K value which is at 1. I want ti interpoliate T(z) of K.

2 次查看（过去 30 天）
Ammar Anayi2021-10-14
%a)
a = 0.01; b = 0.02; % enheten meter
Ti = 723; % Dirichlet, enheten K
Te = 293; % Neumann, enheten K
K = 315;
N = 400; % antal delintervall
h = (b-a)/N; % nÃ¤tstorlek
r = a:h:b; % punkter xj, b+h Ã¤r spÃ¶kpunkt;
u_exact = 0; % exakt lÃ¶sning
% Matrisen A
A = zeros(N+2,N+2); %inkludera rad fÃ¶r spÃ¶kpunkten
for i = 2:N+1
A(i,i-1)=((1/h.^2)-1/(2.*h.*r(i)));
A(i,i) = -2/h.^2;
A(i,i+1)=((1/h.^2)+(1/(2.*h.*r(i))));
end
A(1,1) = 1; % FÃ¶r Dirichlet RV
A(N+2, N) = -1/(2*h);
A(N+2,N+1) = K;
A(N+2,N+2) = 1/(2*h);
f = ';
f(1) = Ti;
f(N+2)=K*Te;
ftrans = f';
T = A\ftrans;
plot( r(1:N+1) , T(1:N+1) ); %plotta inte spÃ¶kpunkten!
z = find(r==0.02);
T(z)
%% b)
% K100 ska finnas fÃ¶r att yttertemp skall ej nÃ¥ 100 grader celsius (373 K)
% u(0.02) ska vara en funktion av K, dÃ¥ K Ã¤ndras kommer u(0.02) att Ã¤ndras
% tills att vi nÃ¥r ett vÃ¤rde som Ã¤r mindre Ã¤n 373K.
K1 = 1;
K2 = 10;
K3 = 20;
K4 = 30;
T1 = 717.1204;
T2 = 670.6470;
T3 = 629.6585;
T4 = 596.6963;
T5 = 373;
KI = [K1 K2 K3 K4 ];
TI = [T1 T2 T3 T4 T5];
Points = [1 2 3 4 5];
I = interp1(KI,TI,Points, 'cubic')
% I calculated by hand and the interpoliation is not linear, så i try cubic but do not know. I want to
% find a K where the final temp och T(z) is less than 373 kelvin.

回答（1 个）

Hi Ammar,
Please find proper values for 'query points' as defined by the variable "Points" here.
Also, provide a Value for variable "KI" as it should be of the same length as the variable "TI."
Below is an example of doing so.
%% b)
% K100 must be present so that the outside temperature does not reach 100 degrees Celsius (373 K)
% u (0.02) must be a function of K, then change K,
% u (0.02) change until we reach a value less than 373K
KI = [1 10 20 30 40];
TI = [717.1204 670.6470 629.6585 596.6963 373];
Points = [1:0.1:40];
I = interp1(KI,TI,Points,'spline');
plot(I) Please refer to the MATLAB Documentation page on 'interp1'.

Community Treasure Hunt

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

Start Hunting!