Professional Documents
Culture Documents
Salmon
Salmon
mat')
%%Problem 1
xfine = 0:1:80;
yfineOrig = polyval(coeff,xfine);
salmon_2k18 = yfineOrig(81)
n = length(t);
y_predicted = polyval(coeff,t);
yfine2 = polyval(coeff2,xfine);
salmon_2k18_2 = yfine2(81)
yfine5 = polyval(coeff5,xfine);
salmon_2k18_5 = yfine5(81)
yfine20 = polyval(coeff20,xfine);
salmon_2k18_20 = yfine20(81)
%%Exponential Problem%%
%salmon = y
%y=No*e^(rt)
% ln(y) = ln(No*e^(rt))
%ln(y) = ln(No) + ln(e^(rt))
%ln(y) = ln(No) + rt
%z = ln(y) and A = ln(No)
%z = A + rt
z = log(salmon);
coeffs = polyfit(t, z, 1);
r = coeffs(1);
A = coeffs(2);
No = exp(coeffs(2));
yfine_exp = No * exp(r*xfine);
salmon_exp_2k18 = yfine_exp(81);
%%fminsearch%%
f = @(v)(rms_error910210(v(1), v(2), v(3), t, salmon)); % v holds a, b , c %@v is wrapper
vmin = fminsearch(f, [.001; -.01; 10]); % plugs guesses into v, from function f, which then goes to rms error
a = vmin(1);
b = vmin(2);
c = vmin(3);