How can I save and plot all values of x and y for each value of V? x and y values are in the vertical axis and V in the horizontal axis in the graphic

조회 수: 1 (최근 30일)
V=[1,2,3,4];
i=1;
while i<=4
syms x y
eqn1 = V(i)*x + y == 2;
eqn2 = -x + y == 3;
sol = solve([eqn1, eqn2], [x, y]);
xSol = double(sol.x);
ySol = double(sol.y);
end

채택된 답변

Star Strider
Star Strider 2021년 1월 26일
편집: Star Strider 2021년 1월 26일
Try this instead:
V=[1,2,3,4];
for k = 1:numel(V)
xy(:,k) = [V(k) 1; -1 1] \ [2; 3];
end
figure
plot3(xy(1,:), xy(2,:), V, '-p')
grid
view(30, 30)
xlabel('x')
ylabel('y')
zlabel('V')
axis([-0.6 -0.1 2.4 2.9 0 5])
text(xy(1,:), xy(2,:), V, compose('V = %.1f',V), 'HorizontalAlignment','right', 'VerticalAlignment','middle')
producing:
EDIT — (26 Jan 2021 at 13:54)
Added plot image.
  댓글 수: 8
Pablo Zarco
Pablo Zarco 2021년 1월 27일
ok Thank you very much, this is helping me a lot. One more last question, if there was another 2 vectors like Vv multipling the y's like this:
Vv*x + Pp*y = 2;
-x + Qqy = 3
it will be like this right?
V=[1,2,3,4];
Q=[1,5,7,4];
P=[1,6,3,9];
xyfcn = @(b,Vv) [(Vv*b(1) + Pp*b(2) - 2); (-b(1) + Qq*b(2) - 3)]
for k = 1:numel(V)
xy(:,k) = fsolve(@(b)xyfcn(b,V(k),P(k),Q(k)), rand(2,1));
end
Star Strider
Star Strider 2021년 1월 27일
As always, my pleasure!
That would work, however ‘syfcn’ would need to be changed slightrly to accommodate the additional arguments:
xyfcn = @(b,Vv,Pp,Qq) [(Vv*b(1) + Pp*b(2) - 2); (-b(1) + Qq*b(2) - 3)];
and then this works:
V=[1,2,3,4];
Q=[1,5,7,4];
P=[1,6,3,9];
xyfcn = @(b,Vv,Pp,Qq) [(Vv*b(1) + Pp*b(2) - 2); (-b(1) + Qq*b(2) - 3)]
xy = zeros(2, numel(V));
for k = 1:numel(V)
xy(:,k) = fsolve(@(b)xyfcn(b,V(k),P(k),Q(k)), rand(2,1));
end
figure
plot3(xy(1,:), xy(2,:), V, '-p')
grid
view(150, 30)
xlabel('x')
ylabel('y')
zlabel('V')
% axis([-0.6 -0.1 2.4 2.9 0 5])
text(xy(1,:), xy(2,:), V, compose('(V = %.1f, Q = %.1f, P = %.1f)',[V; Q; P]'), 'HorizontalAlignment','center', 'VerticalAlignment','bottom', 'FontSize',8)
However plotting it against the other argument vectors would be a problem, since a 3D plot is the limit. It would still be possible to plot it aginst one of them, possibly using the text call to speecify the othe variables, that I expanded from the original version here.

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

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by