How can I find a numerical approximation of a multivariable non-linear equation?

Viewed 61

I've been working on a project for my engineering school. We have to create a mathematical framework allowing us to understand the transformation from two input angles to one output point. The robot we are working on is a 5 bar parallel kinematic robot.

We have found the equation and we managed to find the trajectory.

We have now the error equation which is really good because, for a given point in space, we can find the angles required to achieve minimum error.

This is the error equation. Now we are struggling to find a way to compute all the angles so that the equation equals zero.

I wanted to visualize the graph from 0 to 2*pi for both variables. But on Octave and Matlab, I always end up with an ill matrix making it impossible to use. And now we just don't know what we can do?

Does anyone have any advice for me?

PS : this is the code I was using :

clear

X = 0.5;
Y = 0.5;
L = 1.0;
E = 1.0;

discret = 0.06;

x = [0:discret:2*pi];
y = [0:discret:2*pi];

[xx, yy] = meshgrid (x, y);

Cx = cos(xx)
Sx = sin(xx)
Cy = cos(yy)
Sy = sin(yy)
D = (((-2*(L*Cx - E)+(2*(E - L*Cy))))/((-2*(L)*Sy)+(2*(L)*Sx)));
K = ((-E+L*Cx)^2 - (E-L*Cy)^2 - (L*Sy)^2 - (L*Sx)^2)/((-2*(L)*Sy)+(2*(L)*Sx));
z = abs(Y - X*D - K);

mesh(x, y, z)
meshc(xx,yy,z) 
xlabel ("theta1");
ylabel ("theta2");
zlabel ("Er(theta1,theta2)");
grid on
1 Answers

The bit about precision is hinting that you are performing matrix division, when in fact judging from your equations, you only seem to need normal array division (i.e. an elementwise/vectorised operation, not a matrix operation).

Simply replace any / or ^ with ./, .^ etc as appropriate. Also, your equations can be simplified significantly to make your code slightly clearer and avoid bugs due to legibility:

clear
X = 0.5;  Y = 0.5;  L = 1.0;  E = 1.0;  stepsize = 0.06;
x = [0 : stepsize : 2*pi];  y = [0 : stepsize : 2*pi];
[xx, yy] = meshgrid (x, y);
Cx = cos(xx);  Sx = sin(xx);  Cy = cos(yy);  Sy = sin(yy);
D  = ( Cy + Cx - 2 .* E/L ) ./ ( Sy - Sx );
K  = 0.5 .* ( Sy.^2 + Sx.^2 + (Cy - E/L).^2 - (Cx - E/L).^2 ) ./ (Sy-Sx);
z  = abs(Y - X .* D - K);

surf(x, y, z, 'edgecolor', 'none', 'facecolor', 'interp' )
set( gcf, 'colormap', hot(256), 'color', 'k' )
set( gca, 'gridcolormode', 'manual', 'gridlinestyle', '-', 'gridcolor', 'w', 'gridalpha', 0.1, 'fontsize', 16, 'color', [0.2, 0.2, 0.2], 'xcolor', [0.8,0.8,0.8], 'ycolor', [0.8,0.8,0.8], 'zcolor', [0.8,0.8,0.8] )
set( get( gca, 'xlabel' ), 'string', '\theta_1', 'fontsize', 36 );
set( get( gca, 'ylabel' ), 'string', '\theta_2', 'fontsize', 36 );
set( get( gca, 'zlabel' ), 'string', {'Er( \theta_1, \theta_2 )',''}, 'fontsize', 36 );
view( 15, 30 );
Related