6 views (last 30 days)

I have a nonlinear system of equations, and i would like to formulate the jacobian matrix in matlab symbolic tool box and then use the matlabfunction to convert the jacobian matrix to numerical matlab. The nonlinear equations are

from these equations a total of

defines the nonlinear equations. My matlab code gives error when I try to define the indexes j,k,and i. Below is my code

clear all;

close all;

clc

syms x k y beta theta chi i j

j=1:20

k=1:15

i=1:20

S(j)=symsum((x^k/y(k)*(beta(i)+1/5*(c+7))*chi*sin(theta)),k,1,10)

S(j)=symsum((x^k/y(k)*(beta(i)+1/5*(x^2*c+7))*chi*cos(theta)),k,1,10)

Thanks

Walter Roberson
on 13 Sep 2016

The variable in symsum() cannot be used to index anything. You need to construct the vector of individual values and then sum() them.

For any individual k, how do you decide whether to add or subtract the 1/5* term? Or do you do both, thereby constructing 2^20 entries for Sj (all the possible combinations of plus and minus) ?

Your equations are for Sj but they do not involve j at any point: instead they use the undefined i .

I notice that both of your equations define Sj . Is the implication that the two Sj must equal each other?

Walter Roberson
on 15 Sep 2016

Instead of

S(j)=symsum((x^k/y(k)*(beta(i)+1/5*(c+7))*chi*sin(theta)),k,1,10)

you would use

syms c chi theta i S_1(j) S_2(j) x

y = sym('y', [1, 10]);

xk = x.^(1:10);

yk = y(1:10);

beta_i = evalin(symengine, 'Beta[i]');

term_1a = xk./yk .* (beta_i + 1/5*(c+7) );

term_1b = xk./yk .* (beta_i + 1/5*(x.^2 * c + 7) );

sum_term_1a = sum(term_1a);

sum_term_1b = sum(term_1b);

term_2a = chi * sin(theta);

term_2b = chi * cos(theta);

S_1(j) = sum_term_1a + term_2a;

S_2(j) = sum_term_1b + term_2b;

Unfortunately, it is not practical to generate a symbol named beta(i) with symbolic i, because the name happens to clash with the beta function. I had to rename it to Beta.

You might notice that the formula created for S(j) is completely independent of j, which is in keeping with your posted equations.

You can proceed from there to

sol = solve(S_1(j), S_2(j), theta, chi);

This is a total guess about what you are trying to solve over.

Unfortunately, at least up to R2016a, MATLAB is not able to solve this in theta and chi. There is a pair of solutions; one of the pair is

chi = (1/5)*x*((x*(x*(x*(x*(x*(x*(x*(x*y8+y9)*y7+y8*y9)*y6+y7*y8*y9)*y5+y6*y7*y8*y9)*y4+y5*y6*y7*y8*y9)*y3+y4*y5*y6*y7*y8*y9)*y2+y3*y4*y5*y6*y7*y8*y9)*y1+y2*y3*y4*y5*y6*y7*y8*y9)*y10+x^9*y1*y2*y3*y4*y5*y6*y7*y8*y9)*((x^4+1)*c^2+10*(Beta(i)+7/5)*(x^2+1)*c+50*(Beta(i)+7/5)^2)^(1/2)/(y9*y8*y7*y6*y5*y4*y3*y2*y10*y1)

theta = arctan(-(7+5*Beta(i)+c)/((x^4+1)*c^2+10*(Beta(i)+7/5)*(x^2+1)*c+50*(Beta(i)+7/5)^2)^(1/2), -(c*x^2+5*Beta(i)+7)/((x^4+1)*c^2+10*(Beta(i)+7/5)*(x^2+1)*c+50*(Beta(i)+7/5)^2)^(1/2))

I am almost certain that your posted equations are wrong.

Opportunities for recent engineering grads.

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

Start Hunting!
## 4 Comments

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/302952-symbolic-computation-of-nonlinear-system-of-equations#comment_390787

⋮## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/302952-symbolic-computation-of-nonlinear-system-of-equations#comment_390787

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/302952-symbolic-computation-of-nonlinear-system-of-equations#comment_390792

⋮## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/302952-symbolic-computation-of-nonlinear-system-of-equations#comment_390792

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/302952-symbolic-computation-of-nonlinear-system-of-equations#comment_390811

⋮## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/302952-symbolic-computation-of-nonlinear-system-of-equations#comment_390811

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/302952-symbolic-computation-of-nonlinear-system-of-equations#comment_391355

⋮## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/302952-symbolic-computation-of-nonlinear-system-of-equations#comment_391355

Sign in to comment.