Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Fitting using fit - i can't fit function without one constant [SOLVED]

조회 수: 1 (최근 30일)
Dave Novotny
Dave Novotny 2016년 2월 21일
마감: MATLAB Answer Bot 2021년 8월 20일
xdata =[2;4;6;8;10;12;14;16;18;20;22;24;26;28;30;32;34;36;38;40;42;44;46;48;50;52;54;56;58;60;62;64;66;68;70;72;74;76;78;80;82;84;86;88;90;92;94;96;98;100;102;104;106;108;110;112;114;116;118;120;122;124;126;128;130;132;134;136;138;140;142;144;146;148;150;152;154;156;158;160;162;164;166;168;170;172;174;176;178;180;182;184;186;188;190;192;194;196;198;200;202;204;206;208;210;212;214;216;218;220;222;224;226;228;230;232;234;236;238;240;242;244;246;248;250;252;254;256;258;260;262;264;266;268;270;272;274;276;278;280;282;284;286;288;290;292;294;296;298;300;302;304;306;308;310;312;314;316;318;320;322;324;326;328;330;332;334;336;338;340;342;344;346;348;350;352;354;356;358;360;362;364;366;368;370;372;374;376;378;380;382;384;386;388;390;392;394;396;398;400;402;404;406;408;410;412;414;416;418;420;422;424;426;428;430;432;434;436;438;440;442;444;446;448;450;452;454;456;458;460;462;464;466;468;470;472;474;476;478;480;482;484;486;488;490;492;494;496;498;500;502;504;506;508;510;512;514;516;518;520;522;524;526;528;530;532;534;536;538;540;542;544;546;548;550;552;554;556;558;560;562;564;566;568;570;572;574;576;578;580;582;584;586;588;590;592;594;596;598;600;602;604;606;608;610;612;614;616;618;620;622;624;626;628;630;632;634;636;638;640;642;644;646;648;650;652;654;656;658;660;662;664;666;668;670;672;674;676;678;680;682;684;686;688;690;692;694;696;698;700;];
ydata =[6.26278000000000;6.27940000000000;6.29269000000000;6.30896000000000;6.32565000000000;6.34450000000000;6.36363000000000;6.38417000000000;6.40600000000000;6.42861000000000;6.45287000000000;6.47694000000000;6.50265000000000;6.52863000000000;6.55545000000000;6.58248000000000;6.61241000000000;6.64140000000000;6.67215000000000;6.70440000000000;6.73921000000000;6.77349000000000;6.80694000000000;6.84360000000000;6.88257000000000;6.92449000000000;6.96402000000000;7.00888000000000;7.05375000000000;7.10521000000000;7.15060000000000;7.20701000000000;7.26205000000000;7.32586000000000;7.38752000000000;7.45242000000000;7.52254000000000;7.59482000000000;7.67024000000000;7.75223000000000;7.84316000000000;7.94434000000000;8.04572000000000;8.15654000000000;8.26832000000000;8.38148000000000;8.51742000000000;8.66219000000000;8.82129000000000;9.01743000000000;9.18593000000000;9.39863000000000;9.63410000000000;9.87180000000000;10.1517900000000;10.4426500000000;10.7669800000000;11.1793100000000;11.5742400000000;12.0537000000000;12.5383000000000;13.1471700000000;13.7884100000000;14.5274100000000;15.3763600000000;16.4006100000000;17.4321700000000;18.7822600000000;20.1929000000000;21.9566200000000;23.8748100000000;26.0285300000000;28.6099000000000;31.4957800000000;34.5462400000000;38.0408100000000;41.4115000000000;44.6820700000000;47.5549700000000;49.6861700000000;50.7152100000000;50.5167400000000;49.1606500000000;46.9576000000000;43.9059000000000;40.5749800000000;37.2196500000000;34.1914900000000;31.1625500000000;28.4358400000000;26.0640300000000;23.9699400000000;22.0409300000000;20.5148100000000;19.1507800000000;17.8273500000000;16.7794000000000;15.8616000000000;15.1213700000000;14.2995600000000;13.7685700000000;13.1762000000000;12.6799500000000;12.1719800000000;11.7519200000000;11.4803200000000;11.1426100000000;10.8368500000000;10.5442300000000;10.3085000000000;10.0368000000000;9.88834000000000;9.67551000000000;9.48363000000000;9.36608000000000;9.27265000000000;9.08908000000000;8.97347000000000;8.89833000000000;8.79253000000000;8.63623000000000;8.52934000000000;8.51371000000000;8.39008000000000;8.35012000000000;8.28834000000000;8.20257000000000;8.16814000000000;8.11012000000000;8.03167000000000;7.94798000000000;7.95019000000000;7.85356000000000;7.86944000000000;7.81313000000000;7.73036000000000;7.73296000000000;7.71208000000000;7.68878000000000;7.64186000000000;7.62196000000000;7.56573000000000;7.55278000000000;7.50182000000000;7.52313000000000;7.48311000000000;7.46321000000000;7.43379000000000;7.41370000000000;7.43937000000000;7.41255000000000;7.35214000000000;7.35149000000000;7.36865000000000;7.33029000000000;7.29716000000000;7.33259000000000;7.28724000000000;7.26471000000000;7.28469000000000;7.25671000000000;7.23911000000000;7.21881000000000;7.21493000000000;7.24416000000000;7.20312000000000;7.18372000000000;7.17888000000000;7.21456000000000;7.18292000000000;7.19141000000000;7.17612000000000;7.14944000000000;7.18426000000000;7.16951000000000;7.15074000000000;7.16711000000000;7.12195000000000;7.14737000000000;7.13399000000000;7.12874000000000;7.13834000000000;7.12009000000000;7.09777000000000;7.13349000000000;7.11243000000000;7.09123000000000;7.12495000000000;7.09671000000000;7.08797000000000;7.10723000000000;7.10744000000000;7.09952000000000;7.10748000000000;7.07403000000000;7.09794000000000;7.08514000000000;7.08594000000000;7.07372000000000;7.08618000000000;7.09023000000000;7.07050000000000;7.10455000000000;7.09986000000000;7.07282000000000;7.08380000000000;7.10040000000000;7.09065000000000;7.09873000000000;7.09675000000000;7.06516000000000;7.06616000000000;7.06367000000000;7.09242000000000;7.08301000000000;7.06902000000000;7.06507000000000;7.09011000000000;7.09149000000000;7.07646000000000;7.06668000000000;7.08081000000000;7.07345000000000;7.08500000000000;7.06823000000000;7.07752000000000;7.06823000000000;7.08645000000000;7.07394000000000;7.07362000000000;7.09206000000000;7.07456000000000;7.10132000000000;7.08230000000000;7.08175000000000;7.09599000000000;7.09607000000000;7.10824000000000;7.09139000000000;7.10343000000000;7.10931000000000;7.11155000000000;7.08993000000000;7.11186000000000;7.10967000000000;7.10978000000000;7.10531000000000;7.11249000000000;7.11793000000000;7.12563000000000;7.10745000000000;7.13187000000000;7.12302000000000;7.12856000000000;7.12965000000000;7.13084000000000;7.13503000000000;7.13169000000000;7.12788000000000;7.14242000000000;7.13205000000000;7.13285000000000;7.13874000000000;7.13289000000000;7.13425000000000;7.15380000000000;7.15028000000000;7.15028000000000;7.16339000000000;7.15580000000000;7.16216000000000;7.15064000000000;7.15770000000000;7.16453000000000;7.17413000000000;7.16926000000000;7.16454000000000;7.18191000000000;7.18848000000000;7.17533000000000;7.18972000000000;7.19136000000000;7.18957000000000;7.19439000000000;7.18856000000000;7.20082000000000;7.20533000000000;7.20983000000000;7.19898000000000;7.20080000000000;7.21860000000000;7.22424000000000;7.22104000000000;7.22217000000000;7.21851000000000;7.22445000000000;7.22685000000000;7.23730000000000;7.23456000000000;7.24186000000000;7.23816000000000;7.24620000000000;7.25104000000000;7.25236000000000;7.24868000000000;7.26102000000000;7.26652000000000;7.26735000000000;7.27097000000000;7.27877000000000;7.28352000000000;7.28030000000000;7.28816000000000;7.28505000000000;7.29451000000000;7.29680000000000;7.30479000000000;7.30681000000000;7.31530000000000;7.31061000000000;7.32153000000000;7.32507000000000;7.32736000000000;7.33086000000000;7.33120000000000;7.33859000000000;7.33640000000000;7.33825000000000;7.34122000000000;7.34435000000000;7.34304000000000;7.34633000000000;7.35141000000000;7.35710000000000;7.36007000000000;7.36046000000000;7.35822000000000;7.36002000000000;7.36166000000000;7.36154000000000;7.36383000000000;7.37286000000000;7.38242000000000;7.37758000000000;7.38408000000000;7.38255000000000;7.38511000000000;7.39150000000000;7.39069000000000;7.38586000000000;];
Re = 5.7;
Le = 0.00025;
Rm = 2.649;
Mm = 0.00002;
Cm = 0.00016;
Bl = 10.5;
[xData_bezmod, yData_bezmod] = prepareCurveData(xdata, ydata);
ft = fittype( 'abs(Re + (1i*2*pi*Le*xData_bezmod) + 1./(Rm+1i*2*pi*xData_bezmod*Mm+1./(1i*Cm*2*pi*xData_bezmod)))', 'independent', 'xData_bezmod', 'dependent', 'yData_bezmod');
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Algorithm = 'Trust-Region';
opts.Display = 'Off';
opts.MaxIter = 1000;
opts.MaxFunEvals = 100;
opts.Robust = 'Off';
opts.StartPoint = [0.0138 0.00025 0.0001 5.7 0.024];
[fitresult, gof] = fit( xData_bezmod, yData_bezmod, ft, opts );
h = plot(fitresult, xData_bezmod, yData_bezmod);
Hi,
I am fitting a function abs(Re + (1i*2*pi*Le*xData_bezmod) + 1./(Rm+1i*2*pi*xData_bezmod*Mm+1./(1i*Cm*2*pi*xData_bezmod))). What I need is to fit it without Re (fit and get only Rm, Mm, Cm and Le, but Re must be still part of the equation) but I am getting this constant from GUI, so I have to write as constant. Is there any solution, for example some solutions using some string "magic".
Thanks for answer
Solution:
a = 'abs(';
b = num2str(Re);
c = ' + (1i*2*pi*Le*xData_bezmod) + 1./(Rm+1i*2*pi*xData_bezmod*Mm+1./(1i*Cm*2*pi*xData_bezmod)))';
final_result = strcat(a,b,c);
ft = fittype(final_result, 'independent', 'xData_bezmod', 'dependent', 'yData_bezmod');

답변 (1개)

jgg
jgg 2016년 2월 22일
Try this:
%xdata = ...; %load your data
%ydata = ...
Le = 0.00025;
Rm = 2.649;
Mm = 0.00002;
Cm = 0.00016;
Bl = 10.5;
[xData_bezmod, yData_bezmod] = prepareCurveData(xdata, ydata);
ft = fittype( 'abs((1i*2*pi*Le*xData_bezmod) + 1./(Rm+1i*2*pi*xData_bezmod*Mm+1./(1i*Cm*2*pi*xData_bezmod)))', 'independent', 'xData_bezmod', 'dependent', 'yData_bezmod');
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Algorithm = 'Trust-Region';
opts.Display = 'Off';
opts.MaxIter = 1000;
opts.MaxFunEvals = 100;
opts.Robust = 'Off';
opts.StartPoint = [0.0138 0.00025 0.0001 0.024];
[fitresult, gof] = fit( xData_bezmod, yData_bezmod, ft, opts );
h = plot(fitresult, xData_bezmod, yData_bezmod);
I get:
fitresult =
General model:
fitresult(xData_bezmod) = abs((1i*2*pi*Le*xData_bezmod) + 1./(Rm+1i*2*pi*xData_bezmod*Mm+
1./(1i*Cm*2*pi*xData_bezmod)))
Coefficients (with 95% confidence bounds):
Cm = 0.007137 (0.006876, 0.007398)
Le = -0.001277 (-0.001369, -0.001184)
Mm = 0.0001371 (0.0001321, 0.0001421)
Rm = 0.01959 (0.01895, 0.02023)
  댓글 수: 2
Dave Novotny
Dave Novotny 2016년 2월 22일
편집: Dave Novotny 2016년 2월 22일
Hi, thank you for your answer, but this is not what I need. Re must be part of the equation I just don't want to fit it. I need four results - Rm, Cm, Mm, Le, but same equation as I wrote.
jgg
jgg 2016년 2월 22일
So, you want it to be set as a parameter? Then just replace it in your model:
Re = 5.7;
Le = 0.00025;
Rm = 2.649;
Mm = 0.00002;
Cm = 0.00016;
Bl = 10.5;
[xData_bezmod, yData_bezmod] = prepareCurveData(xdata, ydata);
ft = fittype( 'abs(5.7 + (1i*2*pi*Le*xData_bezmod) + 1./(Rm+1i*2*pi*xData_bezmod*Mm+1./(1i*Cm*2*pi*xData_bezmod)))', 'independent', 'xData_bezmod', 'dependent', 'yData_bezmod');
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Algorithm = 'Trust-Region';
opts.Display = 'Off';
opts.MaxIter = 1000;
opts.MaxFunEvals = 100;
opts.Robust = 'Off';
opts.StartPoint = [0.0138 0.00025 0.0001 0.024];
[fitresult, gof] = fit( xData_bezmod, yData_bezmod, ft, opts );
h = plot(fitresult, xData_bezmod, yData_bezmod);

Community Treasure Hunt

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

Start Hunting!

Translated by