Hi 泰誠 平山,
私の母国語は日本語ではないので、この質問には英語で答えます。ご理解のほどよろしくお願いいたします。.
I understand that you aim to numerically solve symbolic equations. You are creating 14C3 combinations of your data, and for each combination, solving for the symbolic variables using MATLAB "vpasolve" function and further storing the solutions in an array.
However, due to certain combination lacking solutions, the "vpasolve" halts the calculation with an error. Hence, you are seeking a solution to ensure that calculations continue even when no solutions are available for a combination.
As a solution, you can include a conditional check on the "result" variable to determine if any of the solution for symbolic variables are empty. In the event that they are empty, which occurs when no solution is possible, store "NaN" for such solutions in the solution array "K".
Here is the modified code snippet based on the above logic-
clear;clc;
data = [
2.3 171;
3.5 164;
4.4 156;
5.1 153;
5.7 148;
7.2 140;
8.4 134;
9 131;
10 126;
11.2 123;
12.3 119;
12.7 118;
14 115.5;
15.4 114
];
C = nchoosek(1:length(data(:,1)),3); % All combinations of rows in the data
K = zeros(length(C(:,1)),6); % Storage for p0, p1, Δ
for i = 1:length(C(:,1))
data1 = data(C(i,1),:); % 1st point
data2 = data(C(i,2),:); % 2nd point
data3 = data(C(i,3),:); % 3rd point
% Calculation of the 3-equation 2nd degree
syms p0 p1 Delta
sigma = [1/data1(1,1); 1/data2(1,1); 1/data3(1,1)];
Hv = [data1(1,2); data2(1,2); data3(1,2)];
eq = p0 + p1*Delta*sigma - (p1*Delta^2/3)*sigma.^2 - Hv == 0;
result = vpasolve(eq); % solve(eq)
% Storage of p0, p1, Δ
if (isempty(result.p0) || isempty(result.p1) || isempty(result.Delta))
K(i,1) = NaN;
K(i,2) = NaN;
K(i,3) = NaN;
else
K(i,1) = double(result.p0);
K(i,2) = double(result.p1);
K(i,3) = double(result.Delta);
end
end
Hope this helps you in understanding how to modify your code such that the flow proceeds to completion.
Additionally, refer to the following article for more details about how to use conditional statements in MATLAB.
Regards,
Vinayak Luha