user14751931
user14751931

Reputation:

How to plot a line using its polynomial coefficients?

I have a data and 2 classes. After separating them I want to plot a line between them with final weight vector. Is there a suitable method for my final weight which is 3 by 1 matrix. For example the [1,3,-4] matrix is equivalent to x1+3x2-4=0 equation. How can I draw this equation's line in plot?

Upvotes: 0

Views: 166

Answers (1)

saastn
saastn

Reputation: 6015

You can use fplot to plot a function:

w = [1,3,-4];
% create a function handle for w1*x1+w2*x2+w3 => x2 = -(w1x1+w3)/w2
x2 = @(x1) -(w(1)*x1+w(3))/w(2); 
fplot(x2, [0, 10]);
title('w_1x_1+w_2x_2+w_3 = 0')
xlabel('x_1')
ylabel('x_2')

enter image description here

Upvotes: 2

Related Questions