フィルターのクリア

Display answer in degree

3 ビュー (過去 30 日間)
Ali Ahmed
Ali Ahmed 2023 年 12 月 29 日
コメント済み: Dyuman Joshi 2023 年 12 月 30 日
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

回答 (2 件)

Walter Roberson
Walter Roberson 2023 年 12 月 29 日
disp('Solution (in degrees):');
disp(rad2deg(solution));

Torsten
Torsten 2023 年 12 月 30 日
移動済み: Torsten 2023 年 12 月 30 日
"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 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 12 月 30 日
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().

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSystems of Nonlinear Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by