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 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Pablo Zarco
le 26 Jan 2021
Commenté : Star Strider
le 27 Jan 2021
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
0 commentaires
Réponse acceptée
Star Strider
le 26 Jan 2021
Modifié(e) : Star Strider
le 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 commentaires
Star Strider
le 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Spline Postprocessing dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!