How do I extract values from fitting my custom equation to a data set with multiple data entries?

This is for a lab I have to do for class and am sort of stuck at this point. I have a graph with multiple plots. This is at %Plotting Long Channel. I want to fit the equation below to each one of those data sets to extrapolate the mobility term (u) and Threshold Voltage (Vt) for each Vg value. Vt and u are the fitting parameters. At each Vg value I have data sets of Id vs Vd as you can see in my excel spreedsheet. My values for Vg are 0:0.2:1.2. I have the custom fitting toolbox but I am getting no where with it, errors left and right. I want to fit the equation to each of my data sets and find the mobility term that will fit it to the data. Please ignore the Vt already there. I'm trying to get the Vt two seperate ways then compare.
bd.jpg
% PLOTTING Id vs Vd
clear all;
clc;
%Long Channel
Vd = xlsread('W1umL3um.xlsx', 'C4:C53');
Id0 = xlsread('W1umL3um.xlsx', 'D56:D5105');
Id2 = xlsread('W1umL3um.xlsx', 'F56:F105');
Id4 = xlsread('W1umL3um.xlsx', 'H56:H105');
Id6 = xlsread('W1umL3um.xlsx', 'J56:J105');
Id8 = xlsread('W1umL3um.xlsx', 'L56:L105');
Id10 = xlsread('W1umL3um.xlsx', 'N56:N105');
Id12 = xlsread('W1umL3um.xlsx', 'P56:P105');
%Short Channel
SVd = xlsread('W1umL60nm.xlsx', 'C4:C53');
SId0 = xlsread('W1umL60nm.xlsx', 'D56:D105');
SId2 = xlsread('W1umL60nm.xlsx', 'F56:F105');
SId4 = xlsread('W1umL60nm.xlsx', 'H56:H105');
SId6 = xlsread('W1umL60nm.xlsx', 'J56:J105');
SId8 = xlsread('W1umL60nm.xlsx', 'L56:L105');
SId10 = xlsread('W1umL60nm.xlsx', 'N56:N105');
SId12 = xlsread('W1umL60nm.xlsx', 'P56:P5105');
%Plotting Long Channel
figure('Name', 'Long Channel IdVd curve');
Lp = plot(Vd, Id0, Vd, Id2, Vd, Id4, Vd, Id6, Vd, Id8, Vd, Id10, Vd, Id12);
title('Drain Voltage vs Drain Current at varying Gate Voltages');
xlabel('Drain Voltage (V)');
ylabel('Drain Current (mA/um)');
legend({'Vg = 0V','Vg = 0.2V','Vg = 0.4V','Vg = 0.6V','Vg = 0.8V','Vg = 1.0V','Vg = 1.2V'},'Location','east')
grid on
%Plotting Short Channel
figure('Name', 'Short Channel IdVd curve');
Sp = plot(SVd, SId0, SVd, SId2, SVd, SId4, SVd, SId6, SVd, SId8, SVd, SId10, SVd, SId12);
title('Drain Voltage vs Drain Current at varying Gate Voltages');
xlabel('Drain Voltage (V)');
ylabel('Drain Current (mA/um)');
legend({'Vg = 0V','Vg = 0.2V','Vg = 0.4V','Vg = 0.6V','Vg = 0.8V','Vg = 1.0V','Vg = 1.2V'},'Location','east');
grid on
%Plotting Id vs Vg for Long Channel @ Vd = 0.2040816
Vg = xlsread('W1umL3um.xlsx','For Vt','D5:D11');
VtId = xlsread('W1umL3um.xlsx','For Vt','E5:E11');
dydx = gradient(VtId,mean(diff(Vg))); % Calculate Numerical Derivative At Every Point
[maxslope,idx] = max(dydx); % Find Maximum Slope & Index
x = Vg(idx);
y = VtId(idx);
intcpt = (y - maxslope*x); % Calculate Tangent Line Intercept
tangentline = maxslope*Vg+intcpt; % Calculate Tangent Line
Vt = ((-2E-6)-intcpt)/maxslope % Minumum X-Axis Intercept
figure('Name','Graph to get Vt');
IdVg = plot(Vg, VtId);
hold on
plot(Vg, tangentline, '--');
hold off
xlabel('Gate Voltage (V)');
ylabel('Drain Current (mA/um)');
legend({'Vd = 0.2040816V', 'Tangent'},'Location','northwest')
ylim([0 max(ylim)])
%Vg for the purpose of finding u
%Mobility equation from long channel equation

10 Comments

What are Z, , and L?
There are insufficient data to estimate them, and because they are products of each other, impossible to estimate them uniquely in any event.
In other words, we can get the estimated parameter alpha, where alpha is the product (mu*Z*Ci/L) but unless we know Z, Ci, and L we can't get mu by itself.
Code doesn't run. Please also attach 'W1umL60nm.xlsx'.
My apologies. alpha is the value 0.00575.
Here it is.
I am testing this first with ‘Id0’.
I get a (50x1) column vector for ‘Vd’.
There is nothing in the matrices for either ‘Id0’ or ‘Id2’.
What specific values of ‘Vg’ apply to these data (when I am able to load them)? It is a (1x7) vector.
Thanks for the workbook. We're getting closer to being able to help you but we're not there yet. No, alpha can't be that constant value. I just made up the name alpha and it included the unknown mu, which we're supposed to estimate, so alpha = mu*Z*ci/L CANNOT be a constant. Again, unless we know Z, Ci, and L we can't get mu by itself.
I misunderstood. Alpha = mu*0.00575
Z*Ci/L=0.00575
Vg = 0 corresponds to Id0
Vg = 0.2 corresponds to Id2
.
.
.
Vg = 1.2 corresponds to Id12
Id0 should be the column from, in the file 'W1umL3um.xlsx', 'D56:D5105'.
First of all. Thank you all so much! I would just like to know if the value Vt along with mu can be found.
I am still not getting anything for ‘Id0’. It is an empty matrix. (I am using the file I downloaded previously, since it has the same name.)
I cannot make any sense out of ‘SVd’ and ‘SId0’. They look completely random.

Sign in to comment.

 Accepted Answer

To Everyone who might be interested in the answer. Here is the code I'm using. I've commented some things out so I could plot them all together. I used a curve fitting app but generated the code for it.
clc;
%Long Channel
Vd = xlsread('W1umL3um.xlsx', 'C4:C43');
Id0 = xlsread('W1umL3um.xlsx', 'D56:D95');
Id2 = xlsread('W1umL3um.xlsx', 'F56:F95');
Id4 = xlsread('W1umL3um.xlsx', 'H56:H95');
Id6 = xlsread('W1umL3um.xlsx', 'J56:J95');
Id8 = xlsread('W1umL3um.xlsx', 'L56:L95');
Id10 = xlsread('W1umL3um.xlsx', 'N56:N95');
Id12 = xlsread('W1umL3um.xlsx', 'P56:P95');
% Fit: 'Vg = 0V'.
[xData, yData] = prepareCurveData( Vd, Id0 );
% Set up fittype and options.
ft = fittype( '(a1.*0.00575.*((0-b1).*Vd - (Vd.^2/2)))*1000', 'independent', 'Vd', 'dependent', 'Id' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off'
opts.StartPoint = [0.196595250431208 0.251083857976031];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts )
% Plot fit with data.
figure( 'Name', 'Vg = 0V' );
h1 = plot( fitresult, xData, yData, 'ok')
h1(1).LineWidth = 1;
h1(2).LineWidth = 2;
%legend( h1, 'Id0 vs. Vd', 'Vg = 0V', 'Location', 'NorthEast' );
% Label axes
%xlabel Vd
%ylabel Id0
%grid on
hold on
%Fit: 'Vg = 0.2V'.
[xData, yData] = prepareCurveData( Vd, Id2 );
% Set up fittype and options.
ft = fittype( '(a2.*0.00575.*((0.2-b2).*Vd - (Vd.^2/2)))*1000', 'independent', 'Vd', 'dependent', 'Id' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.162182308193243 0.794284540683907];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts )
% Plot fit with data.
%figure( 'Name', 'Vg = 10.2V' );
h2 = plot( fitresult, xData, yData, 'ok')
h2(1).LineWidth = 1;
h2(2).LineWidth = 2;
%legend( h2, 'Id2 vs. Vd', 'Vg = 10.2V', 'Location', 'NorthEast' );
% Label axes
%xlabel Vd
%ylabel Id2
grid on
% Fit: 'Vg = 0.4V'.
[xData, yData] = prepareCurveData( Vd, Id4 );
% Set up fittype and options.
ft = fittype( '(a3.*0.00575.*((0.4-b3).*Vd - (Vd.^2/2)))*1000', 'independent', 'Vd', 'dependent', 'Id' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.311215042044805 0.528533135506213];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts )
% Plot fit with data.
%figure( 'Name', 'Vg = 0.4V' );
h3 = plot( fitresult, xData, yData, 'ok')
h3(1).LineWidth = 1;
h3(2).LineWidth = 2;
%legend( h3, 'Id4 vs. Vd', 'Vg = 0.4V', 'Location', 'NorthEast' );
% Label axes
%xlabel Vd
%ylabel Id4
%grid on
% Fit: 'Vg = 0.6V'.
[xData, yData] = prepareCurveData( Vd, Id6 );
% Set up fittype and options.
ft = fittype( '(a4.*0.00575.*((0.6-b4).*Vd - (Vd.^2/2)))*1000', 'independent', 'Vd', 'dependent', 'Id' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.165648729499781 0.601981941401637];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts )
% Plot fit with data.
%figure( 'Name', 'Vg = 0.6V' );
h4 = plot( fitresult, xData, yData, 'ok')
h4(1).LineWidth = 1;
h4(2).LineWidth = 2;
%legend( h4, 'Id6 vs. Vd', 'Vg = 0.6V', 'Location', 'NorthEast' );
% Label axes
%xlabel Vd
%ylabel Id6
%grid on
% Fit: 'Vg = 0.8V'.
[xData, yData] = prepareCurveData( Vd, Id8 );
% Set up fittype and options.
ft = fittype( '(a5.*0.00575.*((0.8-b5).*Vd - (Vd.^2/2)))*1000', 'independent', 'Vd', 'dependent', 'Id' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.262971284540144 0.654079098476782];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts )
% Plot fit with data.
%figure( 'Name', 'Vg = 0.8V' );
h5 = plot( fitresult, xData, yData, 'ok')
h5(1).LineWidth = 1;
h5(2).LineWidth = 2;
%legend( h5, 'Id8 vs. Vd', 'Vg = 0.8V', 'Location', 'NorthEast' );
% Label axes
%xlabel Vd
%ylabel Id8
%grid on
% Fit: 'Vg = 1.0V'.
[xData, yData] = prepareCurveData( Vd, Id10 );
% Set up fittype and options.
ft = fittype( '(a6.*0.00575.*((1.0-b6).*Vd - (Vd.^2/2)))*1000', 'independent', 'Vd', 'dependent', 'Id' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.689214503140008 0.748151592823709];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts )
% Plot fit with data.
%figure( 'Name', 'Vg = 1.0V' );
h6 = plot( fitresult, xData, yData, 'ok')
h6(1).LineWidth = 1;
h6(2).LineWidth = 3;
%legend( h6, 'Id10 vs. Vd', 'Vg = 1.0V', 'Location', 'NorthEast' );
% Label axes
%xlabel Vd
%ylabel Id10
%grid on
% Fit: 'Vg = 1.2V'.
[xData, yData] = prepareCurveData( Vd, Id12 );
% Set up fittype and options.
ft = fittype( '(a7.*0.00575.*((1.2-b7).*Vd - (Vd.^2/2)))*1000', 'independent', 'Vd', 'dependent', 'Id12' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.380445846975357 0.567821640725221];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts )
% Plot fit with data.
%figure( 'Name', 'Vg = 1.2V' );
h7 = plot( fitresult, xData, yData, 'ok')
h7(1).LineWidth = 1;
h7(2).LineWidth = 2;
%legend( h7, 'Id vs. Vd', 'Vg = 1.2V', 'Location', 'NorthEast' );
% Label axes
%xlabel Vd
%ylabel Id12
%grid on
grid on
xlabel ('Drain Voltage (V)')
ylabel ('Drain Current (mA/um)')
title ('Drain Current vs Drain Voltage w/ varying Gate Voltage')
hold off

More Answers (1)

I am using this code to estimate your parameters:
Vd = xlsread('W1umL3um.xlsx', 'C4:C53');
Id0 = xlsread('W1umL3um.xlsx', 'D56:D5105');
SVd = xlsread('W1umL60nm.xlsx', 'C4:C53');
SId0 = xlsread('W1umL60nm.xlsx', 'D56:D105');
Vg = 0:0.2:1.2;
% % % b(1) = mu, b(2) = Vt
% Idfcn = @(b,Vd) b(1).*Z*Ci.*(Vg-b(2)).*Vd - Vd.^2/2)./L;
ZCiL = 0.00575;
Idfcn = @(b,Vd) b(1).*ZCiL.*(Vg(1)-b(2)).*Vd - Vd.^2/2;
% [B,fv] = fminsearch(@(b) norm(Id0 - Idfcn(b,Vd)), [1;1]);
[B,fv] = fminsearch(@(b) norm(SId0 - Idfcn(b,SVd)), 1000*rand(2,1));
figure
plot(SVd, SId0, 'p')
hold on
plot(SVd, Idfcn(B,SVd), '-g')
hold off
grid
However, since I cannot use your data (it is either nonexistend or apparently random), I can go not further.

11 Comments

Sorry for the late response it could be that my excel spreedsheet has been updated since then. It seems I have an error in my code Id0 should be D56:D105. Not D5105.
If the 56 to 105 aren;t working you may change 56-105 to 4-53. Sorry.
This is what I'm getting when I run your code. Not getting anything for mu or Vt yet though. Code is below.
Image 3.jpg
Here's the code:
clear all;
clc;
%Long Channel
Vd = xlsread('W1umL3um.xlsx', 'C4:C53');
Id0 = xlsread('W1umL3um.xlsx', 'D56:D5105');
Id2 = xlsread('W1umL3um.xlsx', 'F56:F105');
Id4 = xlsread('W1umL3um.xlsx', 'H56:H105');
Id6 = xlsread('W1umL3um.xlsx', 'J56:J105');
Id8 = xlsread('W1umL3um.xlsx', 'L56:L105');
Id10 = xlsread('W1umL3um.xlsx', 'N56:N105');
Id12 = xlsread('W1umL3um.xlsx', 'P56:P105');
%Short Channel
SVd = xlsread('W1umL60nm.xlsx', 'C4:C53');
SId0 = xlsread('W1umL60nm.xlsx', 'D56:D105');
SId2 = xlsread('W1umL60nm.xlsx', 'F56:F105');
SId4 = xlsread('W1umL60nm.xlsx', 'H56:H105');
SId6 = xlsread('W1umL60nm.xlsx', 'J56:J105');
SId8 = xlsread('W1umL60nm.xlsx', 'L56:L105');
SId10 = xlsread('W1umL60nm.xlsx', 'N56:N105');
SId12 = xlsread('W1umL60nm.xlsx', 'P56:P5105');
Vg = 0:0.2:1.2;
% % % b(1) = mu, b(2) = Vt
% Idfcn = @(b,Vd) b(1).*Z*Ci.*(Vg-b(2)).*Vd - Vd.^2/2)./L;
ZCiL = 0.00575;
Idfcn = @(b,Vd) b(1).*ZCiL.*(Vg(1)-b(2)).*Vd - Vd.^2/2;
% [B,fv] = fminsearch(@(b) norm(Id0 - Idfcn(b,Vd)), [1;1]);
[B,fv] = fminsearch(@(b) norm(SId0 - Idfcn(b,SVd)), 1000*rand(2,1));
figure
plot(SVd, SId0, 'p')
hold on
plot(SVd, Idfcn(B,SVd), '-g')
hold off
grid
That is what I referred to as ‘random’. There is no way to fit your model to those data.
Something is obviously wrong (I believe with the data), so until you sort that, I can go no further.
Here is an updated excel spreadsheet with (I'm pretty sure) with the correct values. I went back and made sure the units in the .xls was correlating correctly to the units of the equation.
Here are some alterations I did to the code you provided me with. You do not need the "Short Channel" values such as SVd or SId. Sorry for any confusion. I just want the equation to fit to the "Long Channel" data.
clear all;
clc;
%Long Channel
Vd = xlsread('W1umL3um.xlsx', 'C4:C53');
Id0 = xlsread('W1umL3um.xlsx', 'R56:R105');
Id2 = xlsread('W1umL3um.xlsx', 'T56:T105');
Id4 = xlsread('W1umL3um.xlsx', 'V56:V105');
Id6 = xlsread('W1umL3um.xlsx', 'X56:X105');
Id8 = xlsread('W1umL3um.xlsx', 'Z56:Z105');
Id10 = xlsread('W1umL3um.xlsx', 'AB56:AB105');
Id12 = xlsread('W1umL3um.xlsx', 'AD56:AD105');
Vg = 0:0.2:1.2;
%%%b(1) = mu, b(2) = Vt
% Idfcn = @(b,Vd) b(1).*Z*Ci.*(Vg-b(2)).*Vd - Vd.^2/2)./L;
ZCiL = 0.00575;
Idfcn = @(b,Vd) (b(1).*ZCiL.*((Vg(7)-b(2)).*Vd - Vd.^2/2)).*1000;
% [B,fv] = fminsearch(@(b) norm(Id0 - Idfcn(b,Vd)), [1;1]);
[B,fv] = fminsearch(@(b) norm(Id0 - Idfcn(b,Vd)), 1000*rand(2,1));
figure
plot(Vd, Id0, '.')
hold on
plot(Vd, Idfcn(B,Vd), '-g')
hold off
grid
Hey Star Strider! I figured it out! I got the fits I need! I wouldn't have gone this far without you!
Here's my final code. I... however have one question. How do I combine all these plots together? I can't figure out how to implement the 'hold'.
clear all;
clc;
%Long Channel
Vd = xlsread('W1umL3um.xlsx', 'C4:C53');
Id0 = xlsread('W1umL3um.xlsx', 'R56:R105');
Id2 = xlsread('W1umL3um.xlsx', 'T56:T105');
Id4 = xlsread('W1umL3um.xlsx', 'V56:V105');
Id6 = xlsread('W1umL3um.xlsx', 'X56:X105');
Id8 = xlsread('W1umL3um.xlsx', 'Z56:Z105');
Id10 = xlsread('W1umL3um.xlsx', 'AB56:AB105');
Id12 = xlsread('W1umL3um.xlsx', 'AD56:AD105');
%{
Vg = 0:0.2:1.2;
%%%b(1) = mu, b(2) = Vt
% Idfcn = @(b,Vd) b(1).*Z*Ci.*(Vg-b(2)).*Vd - Vd.^2/2)./L;
ZCiL = 0.00575;
Idfcn = @(b,Vd) (b(1).*ZCiL.*((Vg(1)-b(2)).*Vd - Vd.^2/2)).*1000;
[B,fv] = fminsearch(@(b) norm(Id0 - Idfcn(b,Vd)), [1;1]);
% [B,fv] = fminsearch(@(b) norm(Id0 - Idfcn(b,Vd)), 1000*rand(2,1));
figure
plot(Vd, Id0, '.')
hold on
plot(Vd, Idfcn(B,Vd), '-g')
hold off
grid
%}
% Fit: 'Vg = 0V'.
[xData, yData] = prepareCurveData( Vd, Id0 );
% Set up fittype and options.
ft = fittype( '(a1.*0.00575.*((0-b1).*Vd - (Vd.^2/2)))*1000', 'independent', 'Vd', 'dependent', 'Id' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off'
opts.StartPoint = [0.196595250431208 0.251083857976031];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts )
% Plot fit with data.
figure( 'Name', 'Vg = 0V' );
h1 = plot( fitresult, xData, yData );
legend( h1, 'Id0 vs. Vd', 'Vg = 0V', 'Location', 'NorthEast' );
% Label axes
xlabel Vd
ylabel Id0
grid on
%Fit: 'Vg = 0.2V'.
[xData, yData] = prepareCurveData( Vd, Id2 );
% Set up fittype and options.
ft = fittype( '(a2.*0.00575.*((0.2-b2).*Vd - (Vd.^2/2)))*1000', 'independent', 'Vd', 'dependent', 'Id' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.162182308193243 0.794284540683907];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts )
% Plot fit with data.
figure( 'Name', 'Vg = 10.2V' );
h2 = plot( fitresult, xData, yData );
legend( h2, 'Id2 vs. Vd', 'Vg = 10.2V', 'Location', 'NorthEast' );
% Label axes
xlabel Vd
ylabel Id2
grid on
% Fit: 'Vg = 0.4V'.
[xData, yData] = prepareCurveData( Vd, Id4 );
% Set up fittype and options.
ft = fittype( '(a3.*0.00575.*((0.4-b3).*Vd - (Vd.^2/2)))*1000', 'independent', 'Vd', 'dependent', 'Id' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.311215042044805 0.528533135506213];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts )
% Plot fit with data.
figure( 'Name', 'Vg = 0.4V' );
h3 = plot( fitresult, xData, yData );
legend( h3, 'Id4 vs. Vd', 'Vg = 0.4V', 'Location', 'NorthEast' );
% Label axes
xlabel Vd
ylabel Id4
grid on
% Fit: 'Vg = 0.6V'.
[xData, yData] = prepareCurveData( Vd, Id6 );
% Set up fittype and options.
ft = fittype( '(a4.*0.00575.*((0.6-b4).*Vd - (Vd.^2/2)))*1000', 'independent', 'Vd', 'dependent', 'Id' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.165648729499781 0.601981941401637];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts )
% Plot fit with data.
figure( 'Name', 'Vg = 0.6V' );
h4 = plot( fitresult, xData, yData );
legend( h4, 'Id6 vs. Vd', 'Vg = 0.6V', 'Location', 'NorthEast' );
% Label axes
xlabel Vd
ylabel Id6
grid on
% Fit: 'Vg = 0.8V'.
[xData, yData] = prepareCurveData( Vd, Id8 );
% Set up fittype and options.
ft = fittype( '(a5.*0.00575.*((0.8-b5).*Vd - (Vd.^2/2)))*1000', 'independent', 'Vd', 'dependent', 'Id' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.262971284540144 0.654079098476782];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts )
% Plot fit with data.
figure( 'Name', 'Vg = 0.8V' );
h5 = plot( fitresult, xData, yData );
legend( h5, 'Id8 vs. Vd', 'Vg = 0.8V', 'Location', 'NorthEast' );
% Label axes
xlabel Vd
ylabel Id8
grid on
% Fit: 'Vg = 1.0V'.
[xData, yData] = prepareCurveData( Vd, Id10 );
% Set up fittype and options.
ft = fittype( '(a6.*0.00575.*((1.0-b6).*Vd - (Vd.^2/2)))*1000', 'independent', 'Vd', 'dependent', 'Id' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.689214503140008 0.748151592823709];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts )
% Plot fit with data.
figure( 'Name', 'Vg = 1.0V' );
h6 = plot( fitresult, xData, yData );
legend( h6, 'Id10 vs. Vd', 'Vg = 1.0V', 'Location', 'NorthEast' );
% Label axes
xlabel Vd
ylabel Id10
grid on
% Fit: 'Vg = 1.2V'.
[xData, yData] = prepareCurveData( Vd, Id12 );
% Set up fittype and options.
ft = fittype( '(a7.*0.00575.*((1.2-b7).*Vd - (Vd.^2/2)))*1000', 'independent', 'Vd', 'dependent', 'Id12' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.380445846975357 0.567821640725221];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts )
% Plot fit with data.
figure( 'Name', 'Vg = 1.2V' );
h7 = plot( fitresult, xData, yData );
legend( h7, 'Id12 vs. Vd', 'Vg = 1.2V', 'Location', 'NorthEast' );
% Label axes
xlabel Vd
ylabel Id12
grid on
Congratulations! Thank you!
I do not have the Curve Fitting Toolbox, so I cannot run your code.
You appear to have several different plots with different legend entries and figure names, so I am not certain what you want to do with all of them. The easiest way may be to combine them as different axes in the same figure, using the subplot (link) function.
If you want them all in the same figure, do something like this:
figure
h1 = plot( fitresult_1, xData, yData, 'DisplayName', 'Vg = 0V');
hold on
h2 = plot( fitresult_2, xData, yData, 'DisplayName', 'Vg = 10.2V');
h3 = plot( fitresult_3, xData, yData, 'DisplayName', 'Vg = 0.4V');
h4 = plot( fitresult_4, xData, yData, 'DisplayName','Vg = 0.6V');
h5 = plot( fitresult_5, xData, yData, 'DisplayName','Vg = 0.8V');
h6 = plot( fitresult_6, xData, yData, 'DisplayName','Vg = 1.0V');
h7 = plot( fitresult_7, xData, yData, 'DisplayName','Vg = 1.2V');
hold off
hl = legend;
hl.Location = 'NE';
grid
That should work. However, since I cannot run your code, I am specifying that my code here is UNTESTED.
Note that this requires that you label each ‘fitresult’ and probably ‘gof’ uniquely. (You might be able to store these as numeric or cell array elements instead. I do not know the variable class the are, so I cannot specify that.)
I will consider running your code with fitting procedures that I have available (Statistics and Machine Learning Toolbox, Optimization Toolbox) to see what the result is, simply out of curiosity.
Hey Star! My final code is below. Wouldn't have gotten here if it weren't for you! Code is below. I generated the code from the curve fitting app. So I don't think you need the app itself. Attached are the updated xls files you'll need to run it!
P.S. I'll probably come back tomorrow with another question or two.
Hey Star... the other question is here. Sorry for being a hassle.
This one is slightly more complicated. I don't know how to use the cftool for this. Cheers!
https://www.mathworks.com/matlabcentral/answers/433470-using-the-curve-fitting-tool-to-find-fitting-parameters-of-an-integral
No hassle, so no worries.
The cftool App is part of the Curve Fitting Toolbox. I do not have it, and cannot download and install it.
With respect to Using the curve fitting tool to find fitting parameters of an integral (the one you linked to), you will need to examine those functions and either use the Symbolic Math Toolbox, or re-write them to accuunt for the multiple arguments in them.
For example:
p = @(Vg,Vt) CoRo*(Vg-Vt);
...
b = @(SVd,Vg,Vt) sqrt(a^2+4*exp(SVd)*(exp(p(Vg,Vt))-1));
and so for all the others.
You will also have to create appropriate symbolic functions if you choose to use the Symbolic Math Toolbox and the matlabFunction function to create your anonymous function to use with integral.
I do have the Symbolic math toolbox. How would it change it?
I have updated the code to what you mentioned.
clc;
% INITIALIZE MATLAB
close all;
clc;
clear all;
syms Vt
syms x
syms Vd
syms Vg
syms Cop %Constant of p
syms r
%Short Channel
SVd = xlsread('W1umL60nm.xlsx', 'C4:C53');
SId0 = xlsread('W1umL60nm.xlsx', 'D56:D105');
SId2 = xlsread('W1umL60nm.xlsx', 'F56:F105');
SId4 = xlsread('W1umL60nm.xlsx', 'H56:H105');
SId6 = xlsread('W1umL60nm.xlsx', 'J56:J105');
SId8 = xlsread('W1umL60nm.xlsx', 'L56:L105');
SId10 = xlsread('W1umL60nm.xlsx', 'N56:N105');
SId12 = xlsread('W1umL60nm.xlsx', 'P56:P105');
%Vg = 0:0.2:1.2;
vd = @(SVd, r) (1/0.026).*r.*SVd; %r is the fitting parameter
% Ro (Density)
Cop = 1.652e+16; %Coefficient of Ro
p = @(Vg, Vt) Cop*(Vg-Vt); %Vt is the fitting parameter
% Breaking down the Integral
a = @(SVd,r) 1+exp(vd(SVd, r));
b = @(SVd,Vg,Vt,r)sqrt(a(SVd,r)^2+4*exp(vd(SVd,r))*(exp(p(Vg, Vt))-1));
u = @(SVd,Vg,Vt,r) log(b(SVd,Vg,Vt)-(1+exp(vd(SVd,r)))-log(2));
f = @(SVd,Vg,Vt,r,x)sqrt(u(SVd,Vg,Vt,r))./(1+exp(u(SVd,Vg,Vt,r)-x));
%F = @(x)integral(@(u)f(u,x),0,inf, 'ArrayValued', true);
int(f, SVd, Vg, r, [0 inf])
Hey Star, here's an updated version of my code. Of course there are errors.
% INITIALIZE MATLAB
close all;
clc;
clear all;
syms Vt
syms x
syms Vd
syms Vg
syms Cop %Constant of p
syms r
Z = 1e-6;
q = 1.6e-19;
kT = 4.11e-21;
m0 = 9.1e-31;
hbar = 1.054e-34;
mt = .2 * m0;
mv = 2.5;
e0 = 8.85e-12;
er = 3.7;
Ci = .0163725;
%Defining Vg
Vg0 = 0;
Vg2 = 0.2;
Vg4 = 0.4;
Vg6 = 0.6;
Vg8 = 0.8;
Vg10 = 1.0;
Vg12 = 1.2;
%Short Channel
SVd = xlsread('W1umL60nm.xlsx', 'C4:C53');
SId0 = xlsread('W1umL60nm.xlsx', 'D56:D105');
SId2 = xlsread('W1umL60nm.xlsx', 'F56:F105');
SId4 = xlsread('W1umL60nm.xlsx', 'H56:H105');
SId6 = xlsread('W1umL60nm.xlsx', 'J56:J105');
SId8 = xlsread('W1umL60nm.xlsx', 'L56:L105');
SId10 = xlsread('W1umL60nm.xlsx', 'N56:N105');
SId12 = xlsread('W1umL60nm.xlsx', 'P56:P105');
Io = (sqrt(2).*q.*((kT)^1.5).*mv.*sqrt(mt))/((pi.^2).*(hbar).^2);
vd = @(Vd) (q.*r.*SVd)/(kT);
Ro = @(Vg) (2.*pi.*(hbar.^2).*Ci.*(Vg-Vt))./(q.*kT.*mt.*mv);
fermi_half = @(x) (x.^0.5)/(1+exp.^(x-a));
fermi_half_vd = @(x) (x.^0.5)/(1+exp.^(x-a+vd(Vd)));
%To get u(Vd, Vg)
a = @(Vd, Vg) sqrt((1 + exp.^(vd(Vd))).^2 + 4.*exp(vd(Vd)).*(math.exp(p(Vg)) - 1));
b = @(Vd)(1 + exp.^(vd(Vd)));
c = log(2);
u = @(Vd, Vg) log(a-b)-c
fermi_half_int = quadgk(fermi_half(x), 0, inf)
fermi_half_vd_int = quadgk(fermi_half_vd(x), 0, inf)

Sign in to comment.

Products

Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!