solving similtanous equations in loop

조회 수: 1 (최근 30일)
Vincent Gambuzza
Vincent Gambuzza 2019년 10월 16일
답변: Star Strider 2019년 10월 16일
given the two vectors
x = [1,2,3,4,5,6,7]
y = [1,2,3,4,5,6,7]
how can i solve the system of equations (this could be any equation)
-3*w*sin(x)+ 5*q*sin(y)-10 = 0
3*w*cos(x) - 5*q*cos(y) = 0
I need to find the variables w and q in matrix form.

답변 (1개)

Star Strider
Star Strider 2019년 10월 16일
One approach:
x = [1,2,3,4,5,6,7];
y = [1,2,3,4,5,6,7];
[X,Y] = meshgrid(x,y);
xv = X(:);
yv = Y(:);
% -3*w*sin(x)+ 5*q*sin(y)-10 = 0
% 3*w*cos(x) - 5*q*cos(y) = 0
FM = @(w,q,x,y) [-3*w*sin(x) 5*q*sin(y)-10; 3*w*cos(x) -5*q*cos(y)];
for k = 1:numel(xv)
B(:,k) = fsolve(@(b) FM(b(1),b(2),xv(k),yv(k)), [100;100]);
end
Here ‘B(1,:)’ is ‘w’, and ‘B(2,:)’ is ‘q’. They are due to the matching ‘xv(k)’ ‘yv(k)’ combineations for each ‘k’.
Experiment to get the result you want.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by