Effacer les filtres
Effacer les filtres

Display answer in degree

3 vues (au cours des 30 derniers jours)
Ali Ahmed
Ali Ahmed le 29 Déc 2023
Commenté : Dyuman Joshi le 30 Déc 2023
Hello my friends,
I am trying solve 4 eqution using the following code
% Define the system of nonlinear equations
equations = @(x) [cos(7*x(1)) + cos(7*x(2)) + cos(7*x(3)) + cos(7*x(4));
cos(11*x(1)) + cos(11*x(2)) + cos(11*x(3)) + cos(11*x(4));
cos(13*x(1)) + cos(13*x(2)) + cos(13*x(3)) + cos(13*x(4));
cos(x(1)) + cos(x(2)) + cos(x(3)) + cos(x(4)) - 3.2];
% Initial guess for the solution (in radians)
initialGuess = [0; 0; 0; 0];
% Solve the system using fsolve
options = optimoptions('fsolve', 'Display', 'off'); % Suppress fsolve display
solution = fsolve(equations, initialGuess, options);
% Display the result
disp('Solution (in radians):');
disp(solution);
how to display the answer in degree
not I am new to matlab and find this code through code generator

Réponses (2)

Walter Roberson
Walter Roberson le 29 Déc 2023
disp('Solution (in degrees):');
disp(rad2deg(solution));

Torsten
Torsten le 30 Déc 2023
Déplacé(e) : Torsten le 30 Déc 2023
"fsolve" is not able to find a solution for your system: the exitflag is -2.
% Define the system of nonlinear equations
equations = @(x) [cos(7*x(1)) + cos(7*x(2)) + cos(7*x(3)) + cos(7*x(4));
cos(11*x(1)) + cos(11*x(2)) + cos(11*x(3)) + cos(11*x(4));
cos(13*x(1)) + cos(13*x(2)) + cos(13*x(3)) + cos(13*x(4));
cos(x(1)) + cos(x(2)) + cos(x(3)) + cos(x(4)) - 3.2];
% Initial guess for the solution (in radians)
initialGuess = [0; 0; 0; 0];
% Solve the system using fsolve
options = optimoptions('fsolve', 'Display', 'off','MaxIterations',10000,'MaxFunctionEvaluations',10000); % Suppress fsolve display
[solution,fval,exitflag] = fsolve(equations, initialGuess, options)
solution = 4×1
0.5655 -0.1262 1.2984 -0.8435
fval = 4×1
-0.0651 0.0450 -0.0062 -0.4298
exitflag = -2
  1 commentaire
Dyuman Joshi
Dyuman Joshi le 30 Déc 2023
There is (atleast) a solution -
syms x [1 4]
eqs = [cos(7*x(1)) + cos(7*x(2)) + cos(7*x(3)) + cos(7*x(4));
cos(11*x(1)) + cos(11*x(2)) + cos(11*x(3)) + cos(11*x(4));
cos(13*x(1)) + cos(13*x(2)) + cos(13*x(3)) + cos(13*x(4));
cos(x(1)) + cos(x(2)) + cos(x(3)) + cos(x(4)) - 3.2]
eqs = 
%solve returns the output via vpasolve()
sol = vpasolve(eqs,x)
sol = struct with fields:
x1: -38.235216532077723407827330267693 x2: 288.35776383136872785096437139067 x3: 21544.805212430975000143326690952 x4: -30767.810938238740147856771781125
sol = struct2array(sol);
subs(eqs, x, sol)
ans = 
However, the values are quite scattered, maybe using a better initial point might result in a solution via fsolve().

Connectez-vous pour commenter.

Catégories

En savoir plus sur Systems of Nonlinear Equations dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by