Skip to content

Instantly share code, notes, and snippets.

@snowch
Last active January 30, 2017 20:28
Show Gist options
  • Save snowch/34c44af34ef08bf3be271134e7baac75 to your computer and use it in GitHub Desktop.
Save snowch/34c44af34ef08bf3be271134e7baac75 to your computer and use it in GitHub Desktop.
octave_system_of_linear_equations_xyz_plot

For this equation:

x + y + z = 1
2x - y + 3z = 4

Setup the axis:

X = linspace(-100,100,10);
Y = linspace(-100,100,10);
[ XX, YY ] = meshgrid(X,Y);

Calculating z coordinate for planes:

ZZ1 = 1 - XX - YY;
ZZ2 = 4/3 - 2/3 * XX + 1/3 *YY;

Displaying:

figure;
hold on;
mesh(XX,YY,ZZ1);
mesh(XX,YY,ZZ2);

Then r to rotate the figure with mouse.

http://stackoverflow.com/questions/23041366/how-to-plot-2-planes-in-gnu-octave

plotv - Plot vectors as lines from origin - https://uk.mathworks.com/help/nnet/ref/plotv.html

% 
% Vector plotting
%  by Aidan Macdonald <address@hidden>
% 
% Given a 2xN matrix M, each column is treated as a
% vector and plotted from (0,0) to the vector.
% Matrices with more that 2 rows simply use the first two
% 

function plotv (M, T='-')
  newplot();
  hold on;
  
  for i = 1:columns(M)
      plot([0, M(1, i)], [0, M(2, i)], T);
  endfor

  hold off;
endfunction

Or https://octave.sourceforge.io/geometry/function/drawArrow.html

urlwrite ("http://downloads.sourceforge.net/octave/geometry-2.1.1.tar.gz?download", "geometry-2.1.1.tar.gz");
pkg install ~/geometry-2.1.1.tar.gz
pkg load geometry


hold on; clf(); drawArrow([0 0 1 1], L=1, W=0.1, R=0.1); hold off;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment