MATLAB-7: 用自定义函数拟合数据

自定义函数

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

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值