Is there a way to vpasolve elementwise?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
John Moseley
am 29 Aug. 2015
Kommentiert: Star Strider
am 30 Aug. 2015
Hello,
I am hoping someone can point me in the right direction with regards to the following problem. I have an equation with two variables, x and y, and an unknown c, and I'd like to solve the equation for c over a range of x and y values. The equation cannot be solved for c analytically. Eventually, I'd like to plot the solutions for c as function of x and y in a contour plot. Below is the code that I thought would work for a much simplified example of the actual problem; this may help define the problem.
x = 1:5;
y = 1:5;
[X,Y] = meshgrid(x,y);
syms c
sol = vpasolve(X + c*Y - 3 == 0,c);
Obviously, this did not work. I'm sure I'm thinking about this wrong way. Any helpful ideas are welcome.
Thank you, John.
0 Kommentare
Akzeptierte Antwort
Star Strider
am 29 Aug. 2015
The contour plot is actually the solution. Solving a two-variable problem like that is one of its hidden benefits.
I’m not quite sure what you want to do, but I solved for ‘c’ here, and then had contour provide the (x,y) coordinates for that over the grid you gave it. Here, I asked it for the coordinates corresponding to c=0:
x = 1:5;
y = 1:5;
[X,Y] = meshgrid(x,y);
F = (3-X)./Y;
sol = contour(X, Y, F, [0 0]);
xy = sol(:,2:end)
The ‘xy’ matrix are the coordinates, x = xy(1,:) and y = xy(2,:). I refer you to the documentation on contour for the details. Substitute other values for the fourth argument to define other values of ‘c’.
6 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Contour Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!