Instructions
Objective
Write a program to implement exponential function in matlab.
Requirements and Specifications
Source Code
function [b,m] = expofit(x,y)
% First, we use linear regression. To do this we need to linearize the
% equation
% we have: y = b*exp(mx). If we apply natural logarithm to both sides we get
% ln(y) = ln(b) + mx
% Then we define:
% Y = ln(y)
% B = ln(b)
% M = m
% X = x
% So we end with the equation:
% Y = B + MX
% Calculate the linearized terms
Y = log(y);
X = x;
% Create matrix of coefficients
A = ones(length(x), 2);
A(:,2) = x;
bv = Y';
% Compute terms
coeffs = inv(A'*A)*A'*bv;
% We get the values of B and M
B = coeffs(1);
M = coeffs(2);
% Now we get the real values of b and m
b = exp(B);
m = M;