Solving an equation with terms that require double summation and products
2 次查看(过去 30 天)
显示 更早的评论
I need to solve the following equation.
I wrote the following code based on the above equation, but I believe I have made a mistake as the final answer is large.
I have attached the *.mat file for reference.
Any assistance would be much appreciated.
% Condition number for the optimal distribution of the hole-drilling depth increments, base on the "Integral Method" for the non-uniform hole-drilling residual stress measurement technique
% Determination of the condition number for the optimal distribution of the hole-drilling depth increments,
% base on the "Integral Method" for the non-uniform hole-drilling residual stress measurement technique.
% The following equation as referenced from this source (see below) is used
% for this determination.
% https://link.springer.com/article/10.1007/BF02331114
% Develop the terms of the equation
% The individual terms of the equation will be developed individually and then brought together.
% Loading the files
% Loading the required variables.
% Loading of the required *.mat file and then the variable.
anp = load("191231_GS_0295_10.mat","aij");
aij = anp.aij
% Length of array
N = length(aij)
% Summation of matrix
aij_2 = aij^2
y1 = sum(aij_2(:))
% Product of the matrix
aii = diag(aij)
aii_2 = aii.^2
% Product of the square of the diagonal of the matrix
y2 = 4*prod(aii_2,"all")
% The complete equation is as follows:
K_A = (y1 + (y1.^2-y2).^0.5)./y2
0 个评论
采纳的回答
David Goodmanson
2020-1-20
编辑:David Goodmanson
2020-1-20
Hi GS,
I reproduced your results and then calculated the equation using for loops, just to make sure, and got 1.8767e37, same as the second way. Anyway,
aij_2 = aij^2
can't really be correct since it squares the entire matrix as a matrix product, but both
aij_2 = aij.^2
and the for loop way of doing things proceed element-by-element.
Such a large result as 10^37, is that expected? The expression depends on the scaling of the matrix, i.e. if every element in the matrix were multiplied by 2, the result would be different. If the result is supposed to be a dimensionless condition number, I would think there would have to be some kind of normalization done on aij before using the expression that you have.
Here's Matlab cond:
cond(aij)
ans = 51.3232
9 个评论
David Goodmanson
2020-1-21
Hi GS, the code looks good, although I think replacing ^0.5 with sqrt looks cleaner, and you don't need N
aij_2 = aij.^2;
y1 = sum(aij_2(:))
aii = diag(aij);
aii_2 = aii.^2;
y2 = 4*prod(aii_2);
K_A = (y1 + sqrt(y1^2-y2))/y2
I probably would have used
y1 = sum(sum(aij_2))
just by personal preference, since it emphasizes that there is a 2d sum, but that's neither here nor there.
Incidentally, abbreviating the supposed condition number K_A by c, then c is one of the solutions to the quadratic
y2*c^2 - 2*y1*c + 1 = 0
I wonder what that means?
更多回答(1 个)
David Goodmanson
2020-1-19
编辑:David Goodmanson
2020-1-19
Hi GS, try
aij_2 = aij.^2
Since y1 and y2 are scalars, there are three dots in the last equation that you can drop. I usually do this because it's neater and provides an extra clue to what the variables are. That's a net savings of two dots, which you can use in another equation sometime.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!