2 views (last 30 days)

surendra kumar Aralapura mariyappa
on 19 Jul 2019

Commented: surendra kumar Aralapura mariyappa
on 19 Jul 2019

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

infinity
on 19 Jul 2019

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

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/472471-regarding-the-matrix-indexing#comment_726074

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/472471-regarding-the-matrix-indexing#comment_726074

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/472471-regarding-the-matrix-indexing#comment_726091

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/472471-regarding-the-matrix-indexing#comment_726091

Sign in to comment.