Add surface based on two vectors in 3D plot
Mostra commenti meno recenti
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)
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Surface and Mesh Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!