function plane that calculates the equation for a plane using: ax+ by + c = z . function input should be 3 points (x,y,z), and output should be a mesh plot with x and y from -10 to 10. in matlab

main.m
function plot_plane(x1, y1, z1, x2, y2, z2, x3, y3, z3)
    A = [x1, y1, 1; x2, y2, 1; x3, y3, 1];
    B = [z1; z2; z3];
    
    % Solve for a, b, and c in the equation ax + by + c = z
    X = linsolve(A, B);
    a = X(1);
    b = X(2);
    c = X(3);
    
    % Generate x and y values from -10 to 10
    [xx, yy] = meshgrid(-10:0.5:10, -10:0.5:10);
    
    % Calculate z values using the plane equation
    zz = a * xx + b * yy + c;
    
    % Create a mesh plot
    mesh(xx, yy, zz);
    
    % Label the axes
    xlabel('X');
    ylabel('Y');
    zlabel('Z');
end

% Example usage
plot_plane(1, 1, 1, -2, 2, 3, 3, -2, -2);
628 chars
28 lines

related categories

gistlibby LogSnag