Hello everyone!
When solving the following equations, I defined variable parameters by syms, but it implied that wasn't correct. I don't know how to do, could you help me solve it? Thank you very much!
Best regards
clc; clear
%Solve nonlinear equations
syms a(-6) a(-5) a(-4) a(-3) a(-2) a(-1) a(0) a(1) a(2) a(3) a(4) a(5) a(6) a(7)
[Sa(-6),Sa(-5),Sa(-4),Sa(-3),Sa(-2),Sa(-1),Sa(-0),Sa(1),Sa(2),Sa(3),Sa(4),Sa(5),Sa(6),Sa(7)] ...
=solve(e(-3)==0,e(-2)==0,e(-1)==0,e(0)==0,e(1)==0,e(2)==0,a(-6)==a(7),a(-5)==a(6), ...
a(-4)==a(5),a(-3)==a(4),a(-2)==a(3),a(-1)==a(2),a(0)==a(1))
function y=di(x)
% Define dirichlet function
y=0.*(x~=0)+1.*(x==0);
end
function F=e(n)
F=9*symsum(a(s),s,-6,7)*symsum(a(t),t,-6,7)*di(9*n+2+3*+s)-di(n);
end

 Réponse acceptée

Torsten
Torsten le 25 Août 2022
Modifié(e) : Torsten le 25 Août 2022
format long
a0 = rand(1,7);
%a0 = [5.3916,0.0342,1.789,0.619,-0.0104,0.2155,0.0575];
options = optimset('MaxFunEvals',1000000,'MaxIter',1000000,'TolFun',1e-14,'TolX',1e-14);
%a = fsolve(@fun,a0,options)
a = lsqnonlin(@fun,a0,[],[],options)
Local minimum possible. lsqnonlin stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
a = 1×7
0.197493709597352 0.281302916777374 0.140651449715022 -0.140651455082789 0.000000000021439 0.140651453041311 -0.140651455260134
norm(fun(a))
ans =
3.040264027305917e-09
function res = fun(a)
A = [fliplr(a),a];
res = zeros(1,7);
for n = -3:3
sum_j = 0.0;
for j = -6:7
aj = A(j+7);
sum_k = 0.0;
for k = -6:7
ak = A(k+7);
deltak = double(9*n+2+3*k+j==0);
sum_k = sum_k + ak*deltak;
end
sum_j = sum_j + aj*sum_k;
end
res(n+4) = 9*sum_j - double(n==0);
end
end

8 commentaires

lei
lei le 26 Août 2022
Hi Torsten,
Thank you very much! It does help for me. And I have some questions.
1) As the result is different after running, whether it implies that there are several solutions about the nonlinear equations.
2) Is there some appoach that give the relation between variable parameters in the above nonlinear equation?
Thank you again.
Best regards
Torsten
Torsten le 26 Août 2022
As the result is different after running, whether it implies that there are several solutions about the nonlinear equations.
The code gives different "solutions" depending on the initial guess for the variables. I cannot decide whether they are really roots of the system.
Is there some appoach that give the relation between variable parameters in the above nonlinear equation?
I don't know what you mean.
lei
lei le 26 Août 2022
Because the difference of "solutions", I think maybe there is a connection between the "solutions". Now I think I misunderstand it. Thank you a lot. And have a nice weekend!
Torsten
Torsten le 26 Août 2022
Because the difference of "solutions", I think maybe there is a connection between the "solutions".
Maybe. But you have a complicated system of 7 equations quadratic in the unknowns. I think it will be impossible to analyze its solutions on a theoretical basis.
Torsten
Torsten le 26 Août 2022
Modifié(e) : Torsten le 29 Août 2022
Here is a solution of your system:
syms sum_j sum_k
a = sym('a',[1 7]);
res = sym('res',[1 7]);
A = [fliplr(a),a];
for n = -3:3
sum_j = 0;
for j = -6:7
aj = A(j+7);
sum_k = 0;
for k = -6:7
ak = A(k+7);
deltak = (9*n+2+3*k+j==0);
sum_k = sum_k + ak*deltak;
end
sum_j = sum_j + aj*sum_k;
end
res(n+4) = 9*sum_j - (n==0);
end
res
res = 
[a1,a2,a3,a4,a5,a6,a7,parameters,conditions] = solve(res==0,'ReturnConditions',1)
a1 = 
a2 = 
a3 = 
a4 = 
a5 = 
a6 = 
a7 = 
parameters = 
z
conditions = 
lei
lei le 29 Août 2022
Hi Torsten,
I am confused that whether it implies that the equations only two exact solutions?
Torsten
Torsten le 29 Août 2022
Modifié(e) : Torsten le 29 Août 2022
I am confused that whether it implies that the equations only two exact solutions?
Seems the solution is parametrized by one parameter (see above).
Torsten
Torsten le 29 Août 2022
@lei comment moved here:
Torsten, thank you very much! The result is what I want. Thanks again and have a nice day!

Connectez-vous pour commenter.

Plus de réponses (0)

Question posée :

lei
le 25 Août 2022

Commenté :

le 29 Août 2022

Community Treasure Hunt

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

Start Hunting!

Translated by