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

2 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Star Strider
Star Strider am 26 Jan. 2021
Bearbeitet: Star Strider am 26 Jan. 2021
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 Kommentare
Pablo Zarco
Pablo Zarco am 27 Jan. 2021
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 am 27 Jan. 2021
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Spline Postprocessing finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by