Add surface based on two vectors in 3D plot
조회 수: 1 (최근 30일)
이전 댓글 표시
In the code below, my aim is to mark the span spanned by the vectors x1 and x2. So I need to add a 2D surface in the 3D plot indicting this span which needs to visually contain the two vectors - so that I can give a sense of what a span is to the students. I tried this with the mesh function but apparently something is wrong. Is my approach wrong? How can I draw this surface?
t = [0 0 0]';
x1 = [1 2 1]';
x2 = [3 1 1]';
y = [3 3 4]';
X = [x1 x2];
B_hat = inv(X'*X)*X'*y;
plot3([t(1) x1(1)],[t(2) x1(2)],[t(3) x1(3)])
hold on
plot3([t(1) x2(1)],[t(2) x2(2)],[t(3) x2(3)])
axis([-1 5 -1 5 -1 5])
grid on
hold on
x1_fit = min(x1):1:max(x1);
x2_fit = min(x2):1:max(x2);
[x1_FIT,x2_FIT] = meshgrid(x1_fit,x2_fit);
y_FIT = B_hat(1)*x1_FIT + B_hat(2)*x2_FIT;
mesh(x1_FIT,x2_FIT,y_FIT)
댓글 수: 0
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!