solving similtanous equations in loop

1 visualización (últimos 30 días)
Vincent Gambuzza
Vincent Gambuzza el 16 de Oct. de 2019
Respondida: Star Strider el 16 de Oct. de 2019
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.

Respuestas (1)

Star Strider
Star Strider el 16 de Oct. de 2019
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.

Community Treasure Hunt

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

Start Hunting!

Translated by