Regarding the matrix indexing,

1 次查看(过去 30 天)
Hello all,
I have one problem in assigning index to the matrix.
I have two solver, one is mine and another is my professor.
This is mine:
function T = Euler_explicit(T_0, L, P,C, h,i)
A = inv(C)*L; % Conductance and inverse of specific heat capacity
b = inv(C)*P; % Power loss vector and inverse of specific heat capacity
T = zeros(length(T_0),i);
T(:,1) = T_0; % Initial condition T_0(:,1) = 273.50 Ambient temperature of environment
f_1 = f(A, b, T(:,i)); % Calling the differential equation function
T(:, i+1) = T(:,i) + f_1*h; %here I need to change the indexing, but I am not getting how to change it to get one row vector for each iteration _this is second question
end
Below is my professor: Kindly don't ask for the explantion to this solver, this is very complicated to explain here
function[T_akt] = solver_instationaer(T_akt,P,C,h,L)
% Konstante
b = 0.26; % nach Carter S.3
% Berechnung mittels Näherungsverfahren Teil 1 nach Carter
a2 = (0.5-b)/b^2; % nach Carter S. 3
a1 = 1/b-2*a2; % nach Carter S. 3
a0 = 1-a1-a2; % nach Carter S. 3
% Berechnung mittels Näherungsverfahren nach Carter
% C = zeros(n,n); % zur Überprüfung der stationären Lösung
X = (C+b*h*L)\(C*T_akt+b*h*P); % analog zu inv(C+b*h*G)*(C*T_vor+b*h*Q); nach Carter S. 3
Y = (C+b*h*L)\(C*X+b*h*P); % analog zu inv(C+b*h*G)*(C*X+b*h*Q); nach Carter S. 3
T_akt = a0*T_akt+a1*X+a2*Y; % Berechnung des aktuellen Temperaturvektors nach Carter S. 3
end
This is my main function file where I am calling two solver at two different time:
T_akt(1:n,1) = 273.50; % n = 10 in this case
for t = 1:3600
L = -(LA);
for k = 1: n
L(k,k) = -(sum(L(k,:)));
end
T_akt = solver_instationaer(T_akt,P,C,d_T,L); %my professor
% T_akt = Euler_explicit(T_akt, L, P,C, d_T,t); %mine
T1(:,t) = T_akt;
end
When I run the main function file with professor solver, it is giving one row vector T_akt in each iteration like below: for second iteration
273.5615
273.5015
273.5000
273.5000
273.5000
273.5000
273.5000
273.5000
273.5000
273.5000
When I run the main function file with my solver, it is giving the matrix like below: for second iteration, but It should give the new row vector only, not the vector of previous iteration
%previous % new
273.5615 273.5615
273.5015 273.5015
273.5000 273.5000
273.5000 273.5000
273.5000 273.5000
273.5000 273.5000
273.5000 273.5000
273.5000 273.5000
273.5000 273.5000
273.5000 273.5000
question: it gives the answer like above , But I need only one row vector, I mean vector of the respective iteration like my professor answer.
I thinl I need to make some changes in my slover index especially, here, But I need to know what those changes are.
T = zeros(length(T_0),i);
T(:,1) = T_0; % Initial condition T_0(:,1) = 273.50 Ambient temperature of environment
f_1 = f(A, b, T(:,i)); % Calling the differential equation function
T(:, i+1) = T(:,i) + f_1*h; %here I need to change the indexing, but I am not getting how to change it to get one row vector for each iteration _this is second question
end
Kindly help me out in fixing this problem.
Don't Mind two questions at a time, one is simple but another I don't Know?
any suggestions and answers are most welcomed
Thanks in advance
  2 个评论
Guillaume
Guillaume 2019-7-19
I've formatted your post for you. Please learn to use the toolbar to do so yourself next time.

请先登录,再进行评论。

采纳的回答

infinity
infinity 2019-7-19
Hello,
How about if you modify your function like this
function T = Euler_explicit(T_0, L, P,C, h)
A = inv(C)*L; % Conductance and inverse of specific heat capacity
b = inv(C)*P; % Power loss vector and inverse of specific heat capacity
f_1 = f(A, b, T_0); % Calling the differential equation function
T = T_0 + f_1*h; %here I need to change the indexing, but I am not getting how to change it to get one row vector for each iteration _this is second question
end

更多回答(0 个)

类别

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

产品


版本

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by