Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %nonlinear regresion
- clc; clear; close all;
- g = @(x) exp(x);
- s = @(x) 0.25*exp(x/2);
- X = [1, g(2), s(2);
- 1, g(3), s(3);
- 1, g(5), s(5);
- 1, g(10), s(10)];
- Y = [2;
- 5;
- 10;
- 17]
- a = ((((X.')*X)^(-1))*(X.'))*Y
- f = @(x) a(1) + a(2)*g(x) + a(3)*s(x);
- x = 0:0.01:10;
- xs = [2,3,5,10];
- figure(1)
- plot(x,f(x)); hold on; grid on;
- plot(xs,Y,'ro'); hold off;
- ```````````````````````````
- %multivariable_linear_regression
- clc; clear; close all;
- xL=[2 4 6 8 10];
- X=[1, 2, 3;
- 1, 4, 5;
- 1, 5, 7;
- 1, 6, 8 ]
- Y=[5 ;7; 11; 15]
- a = ((((X.')*X)^-1)*(X.'))*Y
- k = 1;
- f = @(x) a(3)*x + a(2)*x + 1;
- x=0:0.01:15;
- figure(1)
- plot(x,f(x))
- -1.8 + (-1.4)*4+3*5
- ~`````````````````````````````````````````````
- %linear regresion matrix form
- clc; clear; close all;
- xL=[2 4 6 8 10];
- X=[2, 1;
- 4, 1;
- 6, 1;
- 8, 1;
- 10, 1]
- Y=[5 ;7; 11; 40; 32]
- a = ((((X.')*X)^-1)*(X.'))*Y
- f = @(x) a(1)*x + a(2)
- x = 0:0.1:10;
- figure(1)
- plot(x, f(x)); grid on; hold on;
- plot(xL, Y, 'ro'); hold off;
- axis([-1,11,-15,50])
- `````````````````````````````````````````````````````````````````````````````
- %liear regression
- clc; clear; close all;
- x=[2 4 6 8 10];
- y=[5 7 11 40 32];
- mx=(sum(x))/length(x);
- my=(sum(y))/length(y);
- for i=1:length(x)
- ap(i)=(x(i)-mx)*(y(i)-my);
- an=sum(ap);
- end
- for k=1:length(x)
- il(k)=(x(k)-mx)^2;
- ilo=sum(il);
- end
- a=(an)/(ilo)
- b=my-a*mx
- wsp=[a,b];
- f=a*x+b;
- plot(x,y,'ro');
- hold on;
- plot(x,f,'green'); % rysowanie i kolory
- axis([0 20 0 50]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement