ML基础教程:线性建模plotlinear

来源:互联网 发布:各种协议的端口号 编辑:程序博客网 时间:2024/05/02 14:33

Plotlinear.m

clear all;close all;

Define two points for the x-axis

x = [-5 5];

Define the different intercepts and gradients to plot

w0 = [0:1:20];w1 = [0:0.4:8];

Plot all of the lines

figure(1);hold offfor i = 1:length(w0)    plot(x,w0(i)+w1(i).*x);    hold all    fprintf('\ny = %g + %g x',w0(i),w1(i));end
y = 0 + 0 xy = 1 + 0.4 xy = 2 + 0.8 xy = 3 + 1.2 xy = 4 + 1.6 xy = 5 + 2 xy = 6 + 2.4 xy = 7 + 2.8 xy = 8 + 3.2 xy = 9 + 3.6 xy = 10 + 4 xy = 11 + 4.4 xy = 12 + 4.8 xy = 13 + 5.2 xy = 14 + 5.6 xy = 15 + 6 xy = 16 + 6.4 xy = 17 + 6.8 xy = 18 + 7.2 xy = 19 + 7.6 xy = 20 + 8 x

Request user input

close all;figure(1);hold offfprintf('\nKeeps plotting lines on the current plot until you quit (ctrl-c)\n');while 1    intercept = str2num(input('Enter intercept:','s'));    gradient = str2num(input('Enter gradient:','s'));    plot(x,intercept + gradient.*x);hold all    fprintf('\n y = %g + %g x\n\n',intercept,gradient);end
Keeps plotting lines on the current plot until you quit (ctrl-c)
Error using ==> inputCannot call INPUT from EVALC.Error in ==> plotlinear at 29    intercept = str2num(input('Enter intercept:','s'));

======

clear all;close all;clc;x =[-4 4];w0 = [-8:1:8];w1 = [0:0.4:8];for i =1:length(w0)    y1 = w0(i)+1.8*x;    y2 = w1(i)*x;    y3 = w0(i)+w1(i)*x;    figure (1);    %plot(x,y1,'-r'),xlabel('x'),ylabel('y1=w0+x'),hold all;    %plot(x,y2,':r'),xlabel('x'),ylabel('y2= w1*x'),hold all;    plot(x,y3,'-'),xlabel('x'),ylabel('y=w0+w1*x'),hold all;    gridend




关于Machine Learning更多讨论与交流,敬请关注本博客和新浪微博songzi_tea.


0 0
原创粉丝点击