Clear Filters
Clear Filters

Error on Symbolic calculation : "Empty sym : 0-by-1"

3 views (last 30 days)
I need the help of people who have excellent talents in calculating using Matlab.
The equations to be implemented through Matlab coding is as follows.
The results to be obtained through this coding is written in "Answer) ~" above.
And, the data related to this problem(or eqution) is below.
I have tried with the following coding but kept getting the same results as the title. I would like to get helpful advice on this part.
I would appreciate it if you could give me a guide on the solution or error cause.
v1 = [393 393 393 393 393 393 393 393 393 393 ; 3850 4340 4760 5320 5740 6160 6580 7140 7980 8960];
v2 = [408 408 408 408 408 408 408 408 408 408 ; 3300 3720 4080 4560 4920 5280 5640 6120 6840 7680];
v3 = [423 423 423 423 423 423 423 423 423 423 ; 2750 3100 3400 3800 4100 4400 4700 5100 5700 6400];
syms B; % parameter Beta
syms BB; % parameter B
syms C;
%------------- equation 1 -------------%
a1_v1 = 0;
a1_v2 = 0;
a1_v3 = 0;
i = 1; % "Stress Lv. 1" in the second term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v1(i, :)))
N = numel(v1(i,j));
a1_v1 = N*log(v1(i+1,j)/C/exp(BB/v1(i,j))) + a1_v1;
end
i = 1; % "Stress Lv. 2" in the second term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v2(i, :)))
N = numel(v2(i,j));
a1_v2 = N*log(v2(i+1,j)/C/exp(BB/v2(i,j))) + a1_v2;
end
i = 1; % "Stress Lv. 3" in the second term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v3(i, :)))
N = numel(v3(i,j));
a1_v3 = N*log(v3(i+1,j)/C/exp(BB/v3(i,j))) + a1_v3;
end
a2_v1 = 0;
a2_v2 = 0;
a2_v3 = 0;
i = 1; % "Stress Lv. 1" in the third term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v1(i, :)))
N = numel(v1(i,j));
a2_v1 = N*(v1(i+1,j)/C/exp(BB/v1(i,j)))^B*log(v1(i+1,j)/C/exp(BB/v1(i,j))) + a2_v1;
end
i = 1; % "Stress Lv. 2" in the third term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v2(i, :)))
N = numel(v2(i,j));
a2_v2 = N*(v2(i+1,j)/C/exp(BB/v2(i,j)))^B*log(v2(i+1,j)/C/exp(BB/v2(i,j))) + a2_v2;
end
i = 1; % "Stress Lv. 3" in the third term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v3(i, :)))
N = numel(v3(i,j));
a2_v3 = N*(v3(i+1,j)/C/exp(BB/v3(i,j)))^B*log(v3(i+1,j)/C/exp(BB/v3(i,j))) + a2_v3;
end
a1 = a1_v1 + a1_v2 + a1_v3;
a2 = a2_v1 + a2_v2 + a2_v3;
N = numel(v1(1,:)) + numel(v2(1,:))+ numel(v3(1,:)); % the first term of ∂Λ/∂β(equation 1)
one = N/B + a1 - a2;
%------------- equation 2 -------------%
b1_v1 = 0;
b1_v2 = 0;
b1_v3 = 0;
i = 1; % "Stress Lv. 1" in the first term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v1(i, :)))
N = numel(v1(i,j));
b1_v1 = N/v1(i,j) + b1_v1;
end
i = 1; % "Stress Lv. 2" in the first term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v2(i, :)))
N = numel(v2(i,j));
b1_v2 = N/v2(i,j) + b1_v2;
end
i = 1; % "Stress Lv. 3" in the first term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v3(i, :)))
N = numel(v3(i,j));
b1_v3 = N/v3(i,j) + b1_v3;
end
b2_v1 = 0;
b2_v2 = 0;
b2_v3 = 0;
i = 1; % "Stress Lv. 1" in the second term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v1(i, :)))
N = numel(v1(i,j));
b2_v1 = N/v1(i,j)*(v1(i+1,j)/C/exp(BB/v1(i,j)))^B+b2_v1;
end
i = 1; % "Stress Lv. 2" in the second term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v2(i, :)))
N = numel(v2(i,j));
b2_v2 = N/v2(i,j)*(v2(i+1,j)/C/exp(BB/v2(i,j)))^B+b2_v2;
end
i = 1; % "Stress Lv. 3" in the second term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v3(i, :)))
N = numel(v3(i,j));
b2_v3 = N/v3(i,j)*(v3(i+1,j)/C/exp(BB/v3(i,j)))^B+b2_v3;
end
b1 = b1_v1 + b1_v2 + b1_v3;
b2 = b2_v1 + b2_v2 + b2_v3;
two = B*(- b1 + b2);
%------------- equation 3 -------------%
c1 = 0;
c2 = 0;
c3 = 0;
i = 1; % "Stress Lv. 1" in the second term of ∂Λ/∂C(equation 3)
for j = 1:(numel(v1(i, :)))
N = numel(v1(i,j));
c1 = N*(v1(i+1,j)/C/exp(BB/v1(i,j)))^B+c1;
end
i = 1; % "Stress Lv. 2" in the second term of ∂Λ/∂C(equation 3)
for j = 1:(numel(v2(i, :)))
N = numel(v2(i,j));
c2 = N*(v2(i+1,j)/C/exp(BB/v2(i,j)))^B+c2;
end
i = 1; % "Stress Lv. 3" in the second term of ∂Λ/∂C(equation 3)
for j = 1:(numel(v3(i, :)))
N = numel(v3(i,j));
c3 = N*(v3(i+1,j)/C/exp(BB/v3(i,j)))^B+c3;
end
N = numel(v1(1,:)) + numel(v2(1,:)) + numel(v3(1,:)); % the first term of ∂Λ/∂C(equation 3)
three = B/C*(- N + (c1 + c2 + c3));
eqns = [one == 0, two == 0, three == 0];
vars = [B BB C];
answer = solve(eqns, vars);
vpa(answer.B)
vpa(answer.BB)
vpa(answer.C)
  5 Comments
John D'Errico
John D'Errico on 1 Sep 2023
Edited: John D'Errico on 1 Sep 2023
In almost all cases I can think of, when a distribution that is normally bounded at zero is given an extra parameter, the third parameter is a translation parameter, allowing the distribution to be bounded by some other value. That is the case of this three parameter Weibull in the stats TB:
In there, you would read:
" If Xhas a two-parameter Weibull distribution, then Y=X+c has a three-parameter Weibull distribution with the added location parameter c."
Torsten
Torsten on 1 Sep 2023
Edited: Torsten on 1 Sep 2023
Do you think equation 1-3 stem from the differentiation of the log-likelihood function of this 3-parameter Weilbull distribution ? The equations look quite special - adopted to some physical reaction-kinetics application. So I think it's better if @J gives the special form to be considered here. Or can you recover /\ from its derivatives ?

Sign in to comment.

Accepted Answer

Torsten
Torsten on 1 Sep 2023
Edited: Torsten on 1 Sep 2023
Try this code.
By the way: numel(v1(i,j)), numel(v2(i,j)) and numel(v3(i,j)) always equals 1 because v1(i,j), v2(i,j) and v3(i,j) is one single scalar value.
format long
v1 = [393 393 393 393 393 393 393 393 393 393 ; 3850 4340 4760 5320 5740 6160 6580 7140 7980 8960];
v2 = [408 408 408 408 408 408 408 408 408 408 ; 3300 3720 4080 4560 4920 5280 5640 6120 6840 7680];
v3 = [423 423 423 423 423 423 423 423 423 423 ; 2750 3100 3400 3800 4100 4400 4700 5100 5700 6400];
x0 = [4,1800,59];
sol = fsolve(@(x)fun(x,v1,v2,v3),x0)
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
sol = 1×3
1.0e+03 * 0.004291582233058 1.861618685614979 0.058984866373623
function res = fun(x,v1,v2,v3)
B = x(1);
BB = x(2);
C = x(3);
%------------- equation 1 -------------%
a1_v1 = 0;
a1_v2 = 0;
a1_v3 = 0;
i = 1; % "Stress Lv. 1" in the second term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v1(i, :)))
N = numel(v1(i,j));
a1_v1 = N*log(v1(i+1,j)/C/exp(BB/v1(i,j))) + a1_v1;
end
i = 1; % "Stress Lv. 2" in the second term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v2(i, :)))
N = numel(v2(i,j));
a1_v2 = N*log(v2(i+1,j)/C/exp(BB/v2(i,j))) + a1_v2;
end
i = 1; % "Stress Lv. 3" in the second term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v3(i, :)))
N = numel(v3(i,j));
a1_v3 = N*log(v3(i+1,j)/C/exp(BB/v3(i,j))) + a1_v3;
end
a2_v1 = 0;
a2_v2 = 0;
a2_v3 = 0;
i = 1; % "Stress Lv. 1" in the third term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v1(i, :)))
N = numel(v1(i,j));
a2_v1 = N*(v1(i+1,j)/C/exp(BB/v1(i,j)))^B*log(v1(i+1,j)/C/exp(BB/v1(i,j))) + a2_v1;
end
i = 1; % "Stress Lv. 2" in the third term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v2(i, :)))
N = numel(v2(i,j));
a2_v2 = N*(v2(i+1,j)/C/exp(BB/v2(i,j)))^B*log(v2(i+1,j)/C/exp(BB/v2(i,j))) + a2_v2;
end
i = 1; % "Stress Lv. 3" in the third term of ∂Λ/∂β(equation 1)
for j = 1:(numel(v3(i, :)))
N = numel(v3(i,j));
a2_v3 = N*(v3(i+1,j)/C/exp(BB/v3(i,j)))^B*log(v3(i+1,j)/C/exp(BB/v3(i,j))) + a2_v3;
end
a1 = a1_v1 + a1_v2 + a1_v3;
a2 = a2_v1 + a2_v2 + a2_v3;
N = numel(v1(1,:)) + numel(v2(1,:))+ numel(v3(1,:)); % the first term of ∂Λ/∂β(equation 1)
one = N/B + a1 - a2;
%------------- equation 2 -------------%
b1_v1 = 0;
b1_v2 = 0;
b1_v3 = 0;
i = 1; % "Stress Lv. 1" in the first term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v1(i, :)))
N = numel(v1(i,j));
b1_v1 = N/v1(i,j) + b1_v1;
end
i = 1; % "Stress Lv. 2" in the first term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v2(i, :)))
N = numel(v2(i,j));
b1_v2 = N/v2(i,j) + b1_v2;
end
i = 1; % "Stress Lv. 3" in the first term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v3(i, :)))
N = numel(v3(i,j));
b1_v3 = N/v3(i,j) + b1_v3;
end
b2_v1 = 0;
b2_v2 = 0;
b2_v3 = 0;
i = 1; % "Stress Lv. 1" in the second term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v1(i, :)))
N = numel(v1(i,j));
b2_v1 = N/v1(i,j)*(v1(i+1,j)/C/exp(BB/v1(i,j)))^B+b2_v1;
end
i = 1; % "Stress Lv. 2" in the second term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v2(i, :)))
N = numel(v2(i,j));
b2_v2 = N/v2(i,j)*(v2(i+1,j)/C/exp(BB/v2(i,j)))^B+b2_v2;
end
i = 1; % "Stress Lv. 3" in the second term of ∂Λ/∂B(equation 2)
for j = 1:(numel(v3(i, :)))
N = numel(v3(i,j));
b2_v3 = N/v3(i,j)*(v3(i+1,j)/C/exp(BB/v3(i,j)))^B+b2_v3;
end
b1 = b1_v1 + b1_v2 + b1_v3;
b2 = b2_v1 + b2_v2 + b2_v3;
two = B*(- b1 + b2);
%------------- equation 3 -------------%
c1 = 0;
c2 = 0;
c3 = 0;
i = 1; % "Stress Lv. 1" in the second term of ∂Λ/∂C(equation 3)
for j = 1:(numel(v1(i, :)))
N = numel(v1(i,j));
c1 = N*(v1(i+1,j)/C/exp(BB/v1(i,j)))^B+c1;
end
i = 1; % "Stress Lv. 2" in the second term of ∂Λ/∂C(equation 3)
for j = 1:(numel(v2(i, :)))
N = numel(v2(i,j));
c2 = N*(v2(i+1,j)/C/exp(BB/v2(i,j)))^B+c2;
end
i = 1; % "Stress Lv. 3" in the second term of ∂Λ/∂C(equation 3)
for j = 1:(numel(v3(i, :)))
N = numel(v3(i,j));
c3 = N*(v3(i+1,j)/C/exp(BB/v3(i,j)))^B+c3;
end
N = numel(v1(1,:)) + numel(v2(1,:)) + numel(v3(1,:)); % the first term of ∂Λ/∂C(equation 3)
three = B/C*(- N + (c1 + c2 + c3));
res = [one,two,three];
end
  3 Comments
Torsten
Torsten on 1 Sep 2023
Edited: Torsten on 2 Sep 2023
Your equations are nonlinear in the parameters - there is no such "foolproof" method you are searching for. Convergence to the "correct" parameters will always depend on your initial values.
If you can write down the probability density function from which you derived the maximum likelihood function /\ , you can try MATLAB's "mle" with this custom probability density function option and your data from above. Maybe using "mle" to determine maximum likelihood estimates for the parameters C, B and beta is more stable and has a greater region of attraction than simply applying a nonlinear solver to d/\ / dp = 0 as I did above.
J
J on 5 Sep 2023
Thanks to you, I was able to get answers to my questions. I am sorry for the delay in adopting the answer. Thank you for your clear help. @Torsten

Sign in to comment.

More Answers (0)

Categories

Find more on Stress and Strain in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!