Error (line 43) Conversion to double from cell is not possible.

2 vues (au cours des 30 derniers jours)
King Emmanuel Manguba
King Emmanuel Manguba le 10 Nov 2022
clear; clc; close all
% Initialize unknown variables:
syms theta3A theta4 theta5 theta6A
r1A = 96.21;
r1B = 191.45;
r2 = 110;
r3A = 288;
r3B = 222;
r4 = 130;
r5 = 182;
r6A = 265;
r6B = 490;
theta1A = 26.03;
theta1B = 90;
theta2_init = 0;
% Initialize Table for the values
N = 360/5; % number of iterations
n = length(linspace(theta2_init,360,N)); % number of rows
sz = [n 5];
varTypes = {'single','double', 'double', 'double', 'double'};
varNames = {'theta2','theta3A', 'theta4','theta5','theta6A'};
T = table('Size',sz,'VariableTypes',varTypes,'VariableNames',varNames);
% Create counter
counter = 1;
for theta2 = theta2_init:5:360
% Loop 1
eqn1 = r2*cosd(theta2) - r3A*cosd(theta3A) - r4*cosd(theta4) + r1A*cosd(theta1A);
eqn2 = r2*sind(theta2) - r3A*sind(theta3A) - r4*sind(theta4) + r1A*sind(theta1A);
% Loop 2
eqn3 = r1B*cosd(theta1B)+ r5*cosd(theta5) + r6A*cosd(theta6A) + r3B*cosd(170 - (180 - theta3A)) - r4*cosd(theta4);
eqn4 = r1B*sind(theta1B)+ r5*sind(theta5) + r6A*sind(theta6A) + r3B*sind(170 - (180 - theta3A)) - r4*sind(theta4);
F = [eqn1, eqn2, eqn3, eqn4];
result = vpasolve(F, [theta3A, theta4, theta5, theta6A]);
T(counter,:) = {theta2,result.theta3A,result.theta4,result.theta5,result.theta6A};
counter = counter + 1;
end
disp(T);
  2 commentaires
Jan
Jan le 10 Nov 2022
Please do not let the readers guess or count, which one is the 43rd line. You have this information available already.
King Emmanuel Manguba
King Emmanuel Manguba le 15 Nov 2022
I'm sorry. Thanks for the reminder.

Connectez-vous pour commenter.

Réponses (2)

Star Strider
Star Strider le 10 Nov 2022
Modifié(e) : Star Strider le 10 Nov 2022
I limited this to three iterations because of time constraints (I’m running it offline and have been for a few minutes, so this will take a while to complete the full set of iterations).
Try this (and then go do something else for a while because it will take a a relatively long time for this to run for all the iterations) —
% clear; clc; close all
% Initialize unknown variables:
syms theta3A theta4 theta5 theta6A
r1A = 96.21;
r1B = 191.45;
r2 = 110;
r3A = 288;
r3B = 222;
r4 = 130;
r5 = 182;
r6A = 265;
r6B = 490;
theta1A = 26.03;
theta1B = 90;
theta2_init = 0;
% Initialize Table for the values
N = 360/5; % number of iterations
n = length(linspace(theta2_init,360,N)); % number of rows
sz = [n 5];
varTypes = {'single','double', 'double', 'double', 'double'};
varNames = {'theta2','theta3A', 'theta4','theta5','theta6A'};
T = table('Size',sz,'VariableTypes',varTypes,'VariableNames',varNames);
% Create counter
% counter = 1;
theta2v = theta2_init:5:360;
for counter = 1:3%numel(theta2v)
theta2 = theta2v(counter);
% Loop 1
eqn1 = r2*cosd(theta2) - r3A*cosd(theta3A) - r4*cosd(theta4) + r1A*cosd(theta1A);
eqn2 = r2*sind(theta2) - r3A*sind(theta3A) - r4*sind(theta4) + r1A*sind(theta1A);
% Loop 2
eqn3 = r1B*cosd(theta1B)+ r5*cosd(theta5) + r6A*cosd(theta6A) + r3B*cosd(170 - (180 - theta3A)) - r4*cosd(theta4);
eqn4 = r1B*sind(theta1B)+ r5*sind(theta5) + r6A*sind(theta6A) + r3B*sind(170 - (180 - theta3A)) - r4*sind(theta4);
F = [eqn1, eqn2, eqn3, eqn4];
result = vpasolve(F, [theta3A, theta4, theta5, theta6A]);
T{counter,:} = [theta2,result.theta3A,result.theta4,result.theta5,result.theta6A];
% counter = counter + 1;
end
disp(T);
theta2 theta3A theta4 theta5 theta6A ______ _______ ______ _______ _______ 0 1069 2291.6 -4074.6 -1654.7 5 -368.63 133.03 4803.9 -3018.2 10 -6.1741 1214.8 -473.79 -209.19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
EDIT — (10 Nov 2022 at 15:08)
On my AMD Ryzen 9 3900 machine, the result was:
Elapsed time is 581.557208 seconds.
equalling about 9.7 minutes.
.
  1 commentaire
Jan
Jan le 11 Nov 2022
Modifié(e) : Jan le 11 Nov 2022
E.g. 17th iteration does not get a solution such that the result.thetaX are empty. Then:
T{counter,:} = [theta2,result.theta3A,result.theta4,result.theta5,result.theta6A];
fills the row with theta2 repeated 5 times. This is confusing if you work with the output later on.

Connectez-vous pour commenter.


Jan
Jan le 10 Nov 2022
Modifié(e) : Jan le 11 Nov 2022
Use the debugger to examine the problem. Type this in the command window:
dbstop if error
and run the code again. When Matlab stops at the error, check the values of the locally used variables.
In your code there is an empty result, because for some parameters no solution is existing. You cannot include an empty result in a table in this way.
Explicitly: The error occurs in the 17th iteration, because no solution is found:
% clear; clc; close all % No brute clearing header...
% Initialize unknown variables:
syms theta3A theta4 theta5 theta6A
r1A = 96.21;
r1B = 191.45;
r2 = 110;
r3A = 288;
r3B = 222;
r4 = 130;
r5 = 182;
r6A = 265;
r6B = 490;
theta1A = 26.03;
theta1B = 90;
theta2_init = 0;
% Initialize Table for the values
N = 360/5; % number of iterations
% ??? n = length(linspace(theta2_init,360,N)); % number of rows
n = N;
sz = [n 5];
varTypes = {'single','double', 'double', 'double', 'double'};
varNames = {'theta2','theta3A', 'theta4','theta5','theta6A'};
T = table('Size',sz,'VariableTypes',varTypes,'VariableNames',varNames);
% Create counter
counter = 1;
for theta2 = theta2_init + 17 * 5 % theta2_init:5:360
% Loop 1
eqn1 = r2*cosd(theta2) - r3A*cosd(theta3A) - r4*cosd(theta4) + r1A*cosd(theta1A);
eqn2 = r2*sind(theta2) - r3A*sind(theta3A) - r4*sind(theta4) + r1A*sind(theta1A);
% Loop 2
eqn3 = r1B*cosd(theta1B)+ r5*cosd(theta5) + r6A*cosd(theta6A) + r3B*cosd(170 - (180 - theta3A)) - r4*cosd(theta4);
eqn4 = r1B*sind(theta1B)+ r5*sind(theta5) + r6A*sind(theta6A) + r3B*sind(170 - (180 - theta3A)) - r4*sind(theta4);
F = [eqn1, eqn2, eqn3, eqn4];
result = vpasolve(F, [theta3A, theta4, theta5, theta6A]);
disp(result)
T(counter,:) = {theta2,result.theta3A,result.theta4,result.theta5,result.theta6A};
counter = counter + 1;
end
theta3A: [0×1 sym] theta4: [0×1 sym] theta5: [0×1 sym] theta6A: [0×1 sym]
Error using ()
Conversion to double from cell is not possible.
[EDITED] A solution is to catch an empty solution:
for theta2 = theta2_init:5:360
... as the original code
result = vpasolve(F, [theta3A, theta4, theta5, theta6A]);
if isempty(result.thetha3)
fprintf('No result for theta2 = %g\n', theta2);
T{counter, :} = [theta2, NaN(1, 4)];
else
T{counter, :} = [theta2,result.theta3A,result.theta4,result.theta5,result.theta6A];
end
counter = counter + 1;
end
BY the way, this line can be simplified:
n = length(linspace(theta2_init,360,N));
to
n = N;
You do not have to create a linearily spaces vector with N elements to measure its length, because it is N.

Community Treasure Hunt

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

Start Hunting!

Translated by