필터 지우기
필터 지우기

How can I plot a line on a plane?

조회 수: 10 (최근 30일)
MJ
MJ 2021년 5월 6일
답변: DGM 2021년 5월 6일
If I have a plane in this following format z = f(x,y) = a + b*x + c*y + d*x^2 + e*x*y + f*y^2 and I have a line in y=f(x) = p1*x^2 + p2*x + p3 format, how can I plot the line on the plane?
For example, if I use hold on to try to plot the two together, the f(x) line gets plotted two-dimensionally flat in z = 0 plane. Instead of the z = 0 plane I would like a specific plane of z = a + b*x + c*y + d*x^2 + e*x*y + f*y^2 format.
It would be better if I could somehow combine the two equations and turn it into a 3D line and only plot that if possible.
  댓글 수: 1
KSSV
KSSV 2021년 5월 6일
Show us the code you have tried.

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

채택된 답변

Walter Roberson
Walter Roberson 2021년 5월 6일
C = randi([-9 9], 1, 9);
a = C(1), b = C(2), c = C(3), d = C(4), e = C(5), f = C(6), p1 = C(7), p2 = C(8), p3 = C(9)
a = 2
b = -6
c = 5
d = 1
e = -7
f = -9
p1 = 5
p2 = -2
p3 = -5
syms x y
z = a + b*x + c*y + d*x^2 + e*x*y + f*y^2
z = 
y1 = p1*x^2 + p2*x + p3
y1 = 
y2 = solve(z == y1, y)
y2 = 
z21 = simplify(subs(z, y, y2(1)))
z21 = 
z22 = simplify(subs(z, y, y2(2)))
z22 = 
fsurf(z, [-10 10], 'edgecolor', 'none');
hold on
fplot3(x, y2(1), z21, [-10 10])
fplot3(x, y2(2), z22, [-10 10])
hold off

추가 답변 (1개)

DGM
DGM 2021년 5월 6일
There are probably a bunch of ways to do this, but I did this:
% plot range
xrange = [-5 5];
yrange = [-5 5];
% I choose to use parameter vectors
a = [1 1 1 1 1 1];
p = [1 1 1]
syms x y
% a surface
z1 = a(1) + a(2)*x + a(3)*y + a(4)*x.^2 + a(5)*x.*y + a(6)*y.^2
% a curve in the x-y plane
y1 = p(1)*x.^2 + p(2)*x + p(3)
% the projection of y1 on z1
z2 = subs(z1,y,y1)
% curve extends beyond plot range, so find the parameter limits for fplot3
% if it extends beyond other edges, you'll have to solve for that too
curvelimits = double(solve(y1==5,x))'; % limiting values of x
h1 = fsurf(z1,[xrange yrange],'edgecolor','none'); hold on
fplot3(x,y1,z2,curvelimits,'linewidth',3)
fplot(x,y1,curvelimits)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by