필터 지우기
필터 지우기

Display answer in degree

조회 수: 4 (최근 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 CenterFile Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by