Initialize values at time = 0

조회 수: 6 (최근 30일)
aroj bhattarai
aroj bhattarai 2020년 10월 22일
댓글: aroj bhattarai 2020년 10월 22일
Dear Matlab users and experts,
In Fortran,
if (TIME.EQ.ZERO)then
Dmat = 0.0;
Dmat_ant = 0.0;
Thetam = 0.0;
Thetam_ant = 0.0;
end
assigns those ZEROS at the beginning of the calculation. Likewise, in Matlab curve fitting, I need to initialze these values to zero at very first value of lambdas = 1.0. Where lambda(:,1) and lambda(:,2) are my two X-axis data and PK2 is Y-axis value to be functionally calculated as shown below. I am a new user to Matlab and it seems the code is not properly checking if conditional statements. Neither those initialized Dmat, Dmat_ant, Thetam and Thetam_ant are displayed in the workspace, nor the code responds if Taum_t >= Taum_max statement. For all values of lambdas, my code computes PK2 = PK2_iso + PK2_aniso which is not correct: after lambdas > 1.8, the else condition with PK2 = (1 - Dmat).*PK2_iso + PK2_aniso should also be computed when Taum_t >= Taum_max.
Can anyone please help me to find where I have mistaken in the code?
Thank you very much in advance.
lambda(:,1) = [1.0, 1.1, 1.2, 1.3, 1.35, 1.4, 1.45, 1.5, 1.55, 1.6, 1.65, 1.7, 1.75, 1.8, 1.85, 1.9, 1.95, 2.00, 2.05, 2.10];
lambda(:,2) = [1.0, 1.1, 1.2, 1.3, 1.35, 1.4, 1.45, 1.5, 1.55, 1.6, 1.65, 1.7, 1.75, 1.8, 1.85, 1.9, 1.95, 2.00, 2.05, 2.10];
if (lambda(:,1) == lambda(1,1)) & (lambda(:,2) == lambda(1,2))
Dmat = 0.0;
Dmat_ant = 0.0;
Thetam = 0.0;
Thetam_ant = 0.0;
end
Taum_max = S0dm;
Taum_t = sqrt(2.*WbarISO);
if Taum_t < Taum_max
PK2 = PK2_iso + PK2_aniso ;
else
Taum_max = Taum_t;
Amat = (gdm./S0dm.^2 - 0.5).^(-1);
Dmat = 1 - (S0dm./Taum_t).* exp(Amat.*(1 - (Taum_t./S0dm)));
delDmat = Dmat - Dmat_ant;
Thetam = Thetam_ant + WbarISO.* delDmat;
Dmat_ant = Dmat;
Thetam_ant = Thetam;
PK2 = (1 - Dmat).*PK2_iso + PK2_aniso ;
end

채택된 답변

Alan Stevens
Alan Stevens 2020년 10월 22일
You probably want to replace
if (lambda(:,1) == lambda(1,1)) & (lambda(:,2) == lambda(1,2))
by
if (lambda(r,1) == lambda(1,1)) && (lambda(r,2) == lambda(1,2))
where r is the row number.
Your original test produces in a vector of values instead of a single value.
  댓글 수: 1
aroj bhattarai
aroj bhattarai 2020년 10월 22일
Hi Alan Stevens,
Your suggestion with defined 'r' in a for loop
if (lambda(r,1) == lambda(1,1)) && (lambda(r,2) == lambda(1,2))
actually gives those initial ZEROS. But I quickly realized that my irresponsiveness of the second Taum_t >= Taum_max is a different issue which is depending on the initial guess during curve fit. If I am unable to find the solution, I will open a separate topic. Thank you for your help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by