自定义函数
function ids = fids(Vgs,mu,Vth)
Ci = 11.5e-9;
W = 15e-3;
L = 10e-6;
ids = 0.5*mu*Ci*W/L*(Vgs-Vth).^2;
end
调用拟合
clear;close all;clc;
x = -30:0.5:30;
y = (0.95+0.1*rand(size(x))).*0.5*15e-3/10e-6*0.1*11.5e-9.*(x-1).^2;
x = x';
y = y';
f=fittype('fids(x,mu,Vth)','independent','x','coefficients',{'mu','Vth'});
% [cfun,rsquare]=fit(x,y,f,'Lower',[0.01 -2],'Upper',[1 3],'StartPoint',[0.2 0]);
[cfun,g,o]=fit(x,y,f,'Lower',[0.01 -2],'Upper',[1 3],'StartPoint',[0.2 0]);
xi=-30:1:30;
yi=cfun(xi);
plot(x,sqrt(y),'ro',xi,sqrt(yi),'b-');
figure
plot(x,y,'ro',xi,yi,'b-');
cfun
coeffvalues(cfun)
confint(cfun)
g.rsquare
输出
cfun =
General model:
cfun(x) = fids(x,mu,Vth)
Coefficients (with 95% confidence bounds):
mu = 0.1004 (0.09992, 0.1009)
Vth = 0.9712 (0.9117, 1.031)
ans =
0.1004 0.9712
ans =
0.0999 0.9117
0.1009 1.0307
ans =
0.9983