# Solve a large composite set of equations numerically

I have the following set of equations:

1:

$$f(x,y,z) = f_xx+f_yy+f_zz + d_1$$

$$g(x,y,z) = g_xx+g_yy+g_zz + d_2$$

where $$f_x,f_y,f_z, d_1, g_x,g_y,g_z, d_2$$ are known scalar constants, and

$$x,y,z \subset(-1e5,1e5)$$

2:

$$r(f,g) = \sqrt{f^2+g^2}$$

$$N_c(f,g) = \sqrt{(ff_x+gg_x)^2 + (ff_y+gg_y)^2 + (ff_z+gg_z)^2}$$

$$N_s = \sqrt{(f_yg_z-f_zg_y)^2+(f_zg_x-f_xg_z)^2+(f_xg_y-f_yg_x)^2}$$

3:

$$v_{zd} = \frac{-V(ff_z+gg_z)tanh(kr)}{N_c} + \frac{V(f_xg_y-f_yg_x)sech(kr)}{N_s}$$

$$v_{xd} = \frac{-V(ff_x+gg_x)tanh(kr)}{N_c} + \frac{V(f_yg_z-f_zg_y)sech(kr)}{N_s}$$

where $$k$$ is unknown number which I want to find.

4:

$$\chi_d = atan2(v_{zd}, v_{xd})$$

$$B_x = \frac{\partial \chi_d}{\partial x}$$

$$B_y = \frac{\partial \chi_d}{\partial y}$$

$$B_z = \frac{\partial \chi_d}{\partial z}$$

I've been informed to find the value of $$k$$ from the last following two inequalities:

5:

$$\sqrt{B_x^2 + B_z^2} \le \frac{7(1-\alpha)\dot{\chi}_{max}}{10V}$$

$$\lvert{B_y}\rvert \le \frac{\alpha\dot{\chi}_{max}}{V}$$

with $$0 < \alpha < 1$$

and $$\dot{\chi}_{max}, V$$ are known constants.

Just to make things little more easier, let $$\alpha = 0.5, \dot{\chi}_{max} = 0.3, V = 50$$

The ultimate problem here is that $$B_x, B_y, B_z$$ do not have explicit symbolic equations because I have to compute them numerically since their direct symbolic equations are too complicated even for the Matlab symbolic engine.

So the question is: how to numerically solve equations (5:) for the variable $$k$$ in Matlab/Ocatve?

I have finally solved this set symbolically. In the original paper which I've used I have noticed the implicit assumption:

$$lim(k*r) = 0$$

Therefore symbolic evaluation gives:

syms fx fy fz d1 gx gy gz d2 real; syms x y z real; syms k positive; syms s positive; syms V positive; syms F G R NC NS; syms chi_rate_max; syms alpha positive;

s = sym(1);

f(x,y,z) = fx*x + fy*y + fz*z + d1; g(x,y,z) = gx*x + gy*y + gz*z + d2;

r(x,y,z) = sqrt(f^2 + g^2); Nc(x,y,z) = sqrt((f*fx + g*gx)^2 + (f*fy + g*gy)^2 + (f*fz + g*gz)^2); Ns = sqrt((fy*gz - fz*gy)^2 + (fz*gx - fx*gz)^2 + (fx*gy - fy*gx)^2);

vx_d(x,y,z) = sym(-1)*V*(f*fx + g*gx)*tanh(k*r)/Nc + s*V*(fy*gz - fz*gy)*sech(k*r)/Ns; vy_d(x,y,z) = sym(-1)*V*(f*fy + g*gy)*tanh(k*r)/Nc + s*V*(fz*gx - fx*gz)*sech(k*r)/Ns; vz_d(x,y,z) = sym(-1)*V*(f*fz + g*gz)*tanh(k*r)/Nc + s*V*(fx*gy - fy*gx)*sech(k*r)/Ns;

chi_d = atan2(vz_d, vx_d);

B_x = diff(chi_d, x);

B_x = subs(B_x, d1 + fx*x + fy*y + fz*z, F); B_x = subs(B_x, d2 + gx*x + gy*y + gz*z, G); B_x = subs(B_x, sqrt(F^2 + G^2), R); B_x = subs(B_x, R*k, 0); B_x = subs(B_x, sqrt((F*fx + G*gx)^2 + (F*fy + G*gy)^2 + (F*fz + G*gz)^2), NC); B_x = subs(B_x, sqrt((fy*gz - fz*gy)^2 + (fz*gx - fx*gz)^2 + (fx*gy - fy*gx)^2), NS); B_x = simplify(B_x);

B_y = diff(chi_d, y); B_y = subs(B_y, d1 + fx*x + fy*y + fz*z, F); B_y = subs(B_y, d2 + gx*x + gy*y + gz*z, G); B_y = subs(B_y, sqrt(F^2 + G^2), R); B_y = subs(B_y, R*k, 0); B_y = subs(B_y, sqrt((F*fx + G*gx)^2 + (F*fy + G*gy)^2 + (F*fz + G*gz)^2), NC); B_y = subs(B_y, sqrt((fy*gz - fz*gy)^2 + (fz*gx - fx*gz)^2 + (fx*gy - fy*gx)^2), NS); B_y = simplify(B_y);

B_z = diff(chi_d, z); B_z = subs(B_z, d1 + fx*x + fy*y + fz*z, F); B_z = subs(B_z, d2 + gx*x + gy*y + gz*z, G); B_z = subs(B_z, sqrt(F^2 + G^2), R); B_z = subs(B_z, R*k, 0); B_z = subs(B_z, sqrt((F*fx + G*gx)^2 + (F*fy + G*gy)^2 + (F*fz + G*gz)^2), NC); B_z = subs(B_z, sqrt((fy*gz - fz*gy)^2 + (fz*gx - fx*gz)^2 + (fx*gy - fy*gx)^2), NS); B_z = simplify(B_z);

ineq1 = sqrt(simplify(B_x^2 + B_z^2)) <= sym(7)*(sym(1)-alpha)*chi_rate_max/(sym(10)*V); ineq2 = abs(B_y) <= alpha*chi_rate_max/V;

These last two inequalities can be solved symbolically or by hand calculations.