how can we solve non-linear equations like this via MATLAB, I am trying to solve it by using following program but it shows error, shown below in the pic? Thanks in advance.

조회 수: 3 (최근 30일)
clc
clear
syms a1 a2 a3 a4
eqn1 = cos(a1)+cos(a2)+ cos(a3)+ cos(a4) ==3
eqn2 = cos(3*a1)+ cos(a3*2)+ cos(3*a3)+ cos(3*a4) ==0
eqn3 = cos(5*a1)+ cos(5*a2)+ cos(5*a3)+ cos(5*a4) ==0
eqn4 = cos(7*a1)+ cos(7*a2)+ cos(7*a3)+ cos(7*a4) ==0
[A,B] = equationsToMatrix([eqn1, eqn2, eqn3, eqn4], [a1, a2, a3, a4])
X = linsolve(A,B)
  댓글 수: 3

댓글을 달려면 로그인하십시오.

답변 (2개)

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam 2020년 9월 14일
You have used cos function and your equations are not linear.
  댓글 수: 1
Muhammad Zain Khan
Muhammad Zain Khan 2020년 9월 14일
편집: Muhammad Zain Khan 2020년 9월 14일
Assalam-o-Alikum Asad! Can you guide me on how to approach the problem?
Edited: thanks I solved it by myself, but your mentioning of cosine, that it is not linear was really helpful. Thank you.

댓글을 달려면 로그인하십시오.


Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam 2020년 9월 14일
eqns = [2*u + v == 0, u - v == 1];
S = solve(eqns,[u v])
clear
syms a1 a2 a3 a4
eqn1 = cos(a1)+cos(a2)+ cos(a3)+ cos(a4) ==3
eqn2 = cos(3*a1)+ cos(a3*2)+ cos(3*a3)+ cos(3*a4) ==0
eqn3 = cos(5*a1)+ cos(5*a2)+ cos(5*a3)+ cos(5*a4) ==0
eqn4 = cos(7*a1)+ cos(7*a2)+ cos(7*a3)+ cos(7*a4) ==0
eqns = [eqn1, eqn2, eqn3, eqn4];
s = solve(eqns,[a1, a2, a3, a4])
  댓글 수: 2
Muhammad Zain Khan
Muhammad Zain Khan 2020년 9월 14일
편집: Muhammad Zain Khan 2020년 9월 14일
The solution you suggested is taking too long to evalute the values or in my case it is not even evaluating. I used this approach to solve the problem: But it gives variable values for 3 equations, (1,2,4) and for 3rd equation it have some non-zero answer.
% MAPPING: b(1) = a1, b(2) = a2, b(3) = a3, b(4) = a4
f = @(b) [cos(b(1))+cos(b(2))+ cos(b(3))+ cos(b(4))-3
cos(3*b(1))+ cos(3*b(2))+ cos(3*b(3))+ cos(3*b(4))
cos(5*b(1))+ cos(5*b(2))+ cos(5*b(3))+ cos(5*b(4))
cos(7*b(1))+ cos(7*b(2))+ cos(7*b(3))+ cos(7*b(4))];
B0 = [0.4090; 0.1893; 4.6979;3.4790]*2*pi;
[B,fv,xf,ops] = fsolve(f, B0);
ps = ['a1'; 'a2'; 'a3'; 'a4'];
fprintf(1, '\n\tParameters:\n')
for k1 = 1:length(B)
fprintf(1, '\t\t%s = % .4f\n', ps(k1,:), B(k1))
end
Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam 2020년 9월 14일
change
cos(5*b(1))
to
cos(5*b(4)) % third equation
in your code. This approach is nemerical solution approach.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by