Vote count:
0
I am trying to use the least squares fit function to solve for the coefficients a, b, and c in the following equation:
N = p * exp(a -bp -cp*t)
Where: N, p, and t are given for 4 known samples.
N = [11611, 9795, 7819, 7134]
p = [1.763, 1.95, 2.322, 2.689]
t = [415.4, 7557.1, 7470.4, 4547.5]
I have tried everything I could think of to make this work. I tried to put the function in a separate file but still get errors when calling it in the lsqcurvefit function.
I would really appreciate any help, thanks for your time!
clear all
close all
clc
% find a,b,c for N = p*exp(a-b*p-c*p*t) given 4 samples of p,t,N
ln = @log; % natural log
n=4; % number of samples
% data
t = [4015.4, 7557.1, 7470.4, 4547.5];
p = [1.763, 1.95, 2.322, 2.689];
G = [11629, 9813, 7837, 7152];
N = G(1:4) - (542/30);
% plot(p,N);
% least squares
x0 = [0,0,0];
fun = @(x,p,t) p.*exp(x(1) - x(2).*p - x(3).*p*t)
x = lsqcurvefit(fun,x0,p,t,N)
% attempt at matrix solver
% A = [1, -p(1), -(p(1)*t(1));
% 1, -p(2), -(p(2)*t(2));
% 1, -p(3), -(p(3)*t(3));
% 1, -p(4), -(p(4)*t(4))];
%
% B = [ln(N(1)) - ln(p(1));
% ln(N(2)) - ln(p(2));
% ln(N(3)) - ln(p(3));
% ln(N(4)) - ln(p(4))];
%
% x = linsolve(A,B)
asked 32 secs ago
Matlab Least Squares Fit for multiple variables
Aucun commentaire:
Enregistrer un commentaire