diff --git a/expon.m b/expon.m new file mode 100644 index 0000000..7f648de --- /dev/null +++ b/expon.m @@ -0,0 +1,15 @@ +% exponential model a * exp(b * x) +% y = a + b x +clear;clc;close all; +x = input("enter values of x:\n"); +y = input("enter values of y:\n"); +Y = log(y); +n = length(x); +coeff = [n sum(x);sum(x) sum(x.^2)]; +f_terms = [sum(Y);sum(x.*Y)]; +results = inv(coeff) * f_terms; +A = results(1); +a = exp(A); +b = results(2); +f = a * exp(b*x); +plot(x, y,'',x, f); \ No newline at end of file diff --git a/growth_rate.m b/growth_rate.m new file mode 100644 index 0000000..b9898b9 --- /dev/null +++ b/growth_rate.m @@ -0,0 +1,19 @@ +% growth rate model (a * x) / (b + x) +% y = a + b x +clear;clc;close all; +x = input("enter values of x:\n"); +y = input("enter values of y:\n"); +%x = [1,2,3,4,5,6] +%y = [2,4,6,8,10,12] +Y = y.^-1; +X = x.^-1; +n = length(x); +coeff = [n sum(X);sum(X) sum(X.^2)]; +f_terms = [sum(Y);sum(X.*Y)]; +results = inv(coeff) * f_terms; +A = results(1); +B = results(2); +a = 1 / A; +b = B * a; +f = (a.*x)./(b+x); +plot(x, y,'',x, f); diff --git a/linear_regression.m b/linear_regression.m new file mode 100644 index 0000000..46d8940 --- /dev/null +++ b/linear_regression.m @@ -0,0 +1,15 @@ +% linear regression +% y = a + b x +clear;clc;close all; +%x = input("enter values of x:\n"); +%y = input("enter values of y:\n"); +x = [1 2 3 4 5]; +y = [2 3 4 5 6]; +n = length(x); +coeff = [sum(x) n;sum(x) sum(x.^2)]; +f_terms = [sum(y);sum(x.*y)]; +results = inv(coeff) * f_terms; +a = results(1); +b = results(2); +f = a + b * x; +plot(x, y,'', x, f); diff --git a/poly.m b/poly.m new file mode 100644 index 0000000..b320aa7 --- /dev/null +++ b/poly.m @@ -0,0 +1,18 @@ +% poly a + b * x + c * x^2 +clear;clc;close all; +x = input("enter values of x:\n"); +y = input("enter values of y:\n"); +n = length(x); +coeff = [n sum(x) sum(x.^2) + sum(x) sum(x.^2) sum(x.^3) + sum(x.^2) sum(x.^3) sum(x.^4)]; +f_terms = [sum(y) + sum(x.*y) + sum((x.^2).*y)]; +results = inv(coeff) * f_terms; +a = results(1); +b = results(2); +c = results(3); + +f = a + b .* x + c .* x.^2; +plot(x, y, '', x, f); \ No newline at end of file diff --git a/power_model.m b/power_model.m new file mode 100644 index 0000000..ce8707d --- /dev/null +++ b/power_model.m @@ -0,0 +1,16 @@ +% power model a * x ^ b +% y = a + b x +clear;clc;close all; +x = input("enter values of x:\n"); +y = input("enter values of y:\n"); +Y = log(y); +X = log(x); +n = length(x); +coeff = [n sum(X);sum(X) sum(X.^2)]; +f_terms = [sum(Y);sum(X.*Y)]; +results = inv(coeff) * f_terms; +A = results(1); +a = exp(A); +b = results(2); +f = a * x.^b; +plot(x, y,'', x, f); \ No newline at end of file