Initialize values at time = 0
4 views (last 30 days)
Show older comments
aroj bhattarai
on 22 Oct 2020
Commented: aroj bhattarai
on 22 Oct 2020
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
0 Comments
Accepted Answer
Alan Stevens
on 22 Oct 2020
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.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!