lsqcurvefit issues due to variables being several orders of magnitu... (2024)

64 次查看(过去 30 天)

显示 更早的评论

Andrew 2024-7-30,19:20

  • 链接

    此问题的直接链接

    https://ww2.mathworks.cn/matlabcentral/answers/2141596-lsqcurvefit-issues-due-to-variables-being-several-orders-of-magnitude-different

  • 链接

    此问题的直接链接

    https://ww2.mathworks.cn/matlabcentral/answers/2141596-lsqcurvefit-issues-due-to-variables-being-several-orders-of-magnitude-different

编辑: Torsten 2024-7-31,10:43

  • data.mat
  • V1.mat
  • Vp.mat

I am trying to use lsqcurvefit to fit an equation to some data in order to solve for a couple variables. I have included the part of the code below that covers this. I am trying to solve for coeff(1) and coeff(2), The problem is that when I run lsqcurvefit, it is just using whatever my initial guesses are and outputting that as the solution. I suspect it is because my values for the coefficients will be several orders of magnitude different. You can kind of get an idea for this by looking at coeff0. Has anyone else run into this problem and/or do you know how to work around it? Any insight would be greatly appreciated.

load('V1.mat')

load('Vp.mat')

load('data.mat')

V = [V1, Vp]; %voltages

a = 1.1792;

b = 0.5;

e = 1.60217662e-19;

Area = 4.7909e-7;

mi = 39.948./(6.022e23.*1000);

coeff0 = [7e10 4]; %initial guess

qn7 = @(coeff, VV) e^1.5*coeff(1)*Area*sqrt(coeff(2)/(2*pi*mi))*100^3*...

(a*(-VV(:,1)/coeff(2)).^b.*tanh(VV(:,2)/(2*coeff(2))) + ...

(a*(-VV(:,1)/coeff(2)).^b - a*(-(VV(:,1)+VV(:,2))/coeff(2)).^b)./(exp(VV(:,2)/coeff(2))+1));

options = optimoptions('lsqcurvefit','Algorithm','levenberg-marquardt','OptimalityTolerance',1e-16,'FunctionTolerance',1e-16);

lb = [];

ub = [];

Unrecognized function or variable 'Ip'.

[vals, resnorm, out, flag] = lsqcurvefit(qn7, coeff0, V, data(:,2),lb,ub);

plot(data(:,1),data(:,2),'x',data(:,1),qn7(vals,V),'b-')

5 个评论

显示 3更早的评论隐藏 3更早的评论

Torsten 2024-7-30,21:09

此评论的直接链接

https://ww2.mathworks.cn/matlabcentral/answers/2141596-lsqcurvefit-issues-due-to-variables-being-several-orders-of-magnitude-different#comment_3224706

  • 链接

    此评论的直接链接

    https://ww2.mathworks.cn/matlabcentral/answers/2141596-lsqcurvefit-issues-due-to-variables-being-several-orders-of-magnitude-different#comment_3224706

编辑:Torsten 2024-7-30,21:14

Andrew 2024-7-30,21:13

此评论的直接链接

https://ww2.mathworks.cn/matlabcentral/answers/2141596-lsqcurvefit-issues-due-to-variables-being-several-orders-of-magnitude-different#comment_3224721

  • 链接

    此评论的直接链接

    https://ww2.mathworks.cn/matlabcentral/answers/2141596-lsqcurvefit-issues-due-to-variables-being-several-orders-of-magnitude-different#comment_3224721

编辑:Andrew 2024-7-30,21:40

Sorry, I thought I changed that. Ip(:,point) is just data(:,2)

Edit: I missed some stuff when I copied and pasted it over. I just fixed it. I clicked the MATLAB online tab and it ran.

dpb 2024-7-30,23:41

此评论的直接链接

https://ww2.mathworks.cn/matlabcentral/answers/2141596-lsqcurvefit-issues-due-to-variables-being-several-orders-of-magnitude-different#comment_3224756

  • 链接

    此评论的直接链接

    https://ww2.mathworks.cn/matlabcentral/answers/2141596-lsqcurvefit-issues-due-to-variables-being-several-orders-of-magnitude-different#comment_3224756

  • data.mat
  • V1.mat
  • Vp.mat

load('V1.mat')

load('Vp.mat')

load('data.mat')

V = [V1, Vp]; %voltages

a = 1.1792;

b = 0.5;

e = 1.60217662e-19;

Area = 4.7909e-7;

mi = 39.948./(6.022e23.*1000);

coeff0 = [6E10 9]; %initial guess

Eqn7 = @(coeff, VV) e^1.5*coeff(1)*Area*sqrt(coeff(2)/(2*pi*mi))*100^3*...

(a*(-VV(:,1)/coeff(2)).^b.*tanh(VV(:,2)/(2*coeff(2))) + ...

(a*(-VV(:,1)/coeff(2)).^b - a*(-(VV(:,1)+VV(:,2))/coeff(2)).^b)./(exp(VV(:,2)/coeff(2))+1));

options = optimoptions('lsqcurvefit','Algorithm','levenberg-marquardt','OptimalityTolerance',1e-16,'FunctionTolerance',1e-16);

lb = [];

ub = [];

[vals, resnorm, out, flag] = lsqcurvefit(Eqn7, coeff0, V, data(:,2),lb,ub);

Initial point is a local minimum.Optimization completed because the size of the gradient at the initial point is less than the value of the optimality tolerance.

plot(data(:,1),data(:,2),'x',data(:,1),Eqn7(vals,V),'b-')

lsqcurvefit issues due to variables being several orders of magnitu... (5)

I ran out of time at the moment, but no matter what I tried for initial guesses, the gradient was calculated to be essentially zero so it thinks it's converged no matter the input guess.

I changed parameters greatly to see the influence each has on the result and purely by trial and error found the above that aren't too terrible.

You may want to investigate the gradient calculations more thoroughly and see what might be going on there...

Andrew 2024-7-31,0:50

此评论的直接链接

https://ww2.mathworks.cn/matlabcentral/answers/2141596-lsqcurvefit-issues-due-to-variables-being-several-orders-of-magnitude-different#comment_3224786

  • 链接

    此评论的直接链接

    https://ww2.mathworks.cn/matlabcentral/answers/2141596-lsqcurvefit-issues-due-to-variables-being-several-orders-of-magnitude-different#comment_3224786

Thank you for the help. How do I look at the gradient calculations?

This is actually one of hundreds of points I need to look at so I need to figure out how to get it to work without me manually finding the best values.

Andrew 2024-7-31,4:34

此评论的直接链接

https://ww2.mathworks.cn/matlabcentral/answers/2141596-lsqcurvefit-issues-due-to-variables-being-several-orders-of-magnitude-different#comment_3224901

  • 链接

    此评论的直接链接

    https://ww2.mathworks.cn/matlabcentral/answers/2141596-lsqcurvefit-issues-due-to-variables-being-several-orders-of-magnitude-different#comment_3224901

编辑:Andrew 2024-7-31,4:55

So I tried scaling the variables and even the equation to see if it did have to do with my variables being to different in terms of order of magnitude. That didn't do anything.

I also tried using the trust-region-reflective algorithm. It didn't improve the fit most of the time. Interesting enough though, I have some data points that were near the edge of my plasma where my densities are pretty low and I didn't get the signature "S" shape I was looking for. Trust-region-reflective did tend to work better for those cases.

I ended messing around with the options and the bounds. The following options and bounds get me a pretty good fit for the majority of my data points. I realized my OptimalityTolerance and FunctionTolerance were causing it to step out. I cranked those down and then it started having issues with the StepTolerance the majority of the time and on occasion the ConstraintTolerance. It appears that the majority of the time, my stepsize is getting extremely small and causing it to step out. I need to look in to how the step size is calculated and figure out why this would be happening when the fit is still pretty far off. Also, my tolerances are probably overkill right now. I was just cranking them down to see what happens, but after a certain point it didn't really make a difference.

options = optimoptions('lsqcurvefit','Algorithm','levenberg-marquardt','OptimalityTolerance',1e-100,'FunctionTolerance',1e-100,'StepTolerance',1e-100,'ConstraintTolerance',1e-100);

lb = [1e8 0];

ub = [1e13 20];

Edit: Adding the following option to the options appears to make it converge succesfully more often.

'ScaleProblem','jacobian'

请先登录,再进行评论。

请先登录,再回答此问题。

回答(1 个)

Torsten 2024-7-31,10:37

  • 链接

    此回答的直接链接

    https://ww2.mathworks.cn/matlabcentral/answers/2141596-lsqcurvefit-issues-due-to-variables-being-several-orders-of-magnitude-different#answer_1492866

  • 链接

    此回答的直接链接

    https://ww2.mathworks.cn/matlabcentral/answers/2141596-lsqcurvefit-issues-due-to-variables-being-several-orders-of-magnitude-different#answer_1492866

编辑:Torsten 2024-7-31,10:43

  • Vp.mat
  • V1.mat
  • data.mat

load('V1.mat')

load('Vp.mat')

load('data.mat')

V = [V1, Vp]; %voltages

a = 1.1792;

b = 0.5;

e = 1.60217662e-19;

Area = 4.7909e-7;

mi = 39.948./(6.022e23.*1000);

coeff0 = [1e-5 10]; %initial guess

Eqn7 = @(coeff, VV) coeff(1)*sqrt(coeff(2))*...

(a*(-VV(:,1)/coeff(2)).^b.*tanh(VV(:,2)/(2*coeff(2))) + ...

(a*(-VV(:,1)/coeff(2)).^b - a*(-(VV(:,1)+VV(:,2))/coeff(2)).^b)./(exp(VV(:,2)/coeff(2))+1));

%options = optimoptions('lsqcurvefit','Algorithm','levenberg-marquardt','OptimalityTolerance',1e-16,'FunctionTolerance',1e-16);

lb = [];

ub = [];

[vals, resnorm, out, flag] = lsqcurvefit(Eqn7, coeff0, V, data(:,2));

Local minimum possible.lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.

plot(data(:,1),data(:,2),'x',data(:,1),Eqn7(vals,V),'b-')

lsqcurvefit issues due to variables being several orders of magnitu... (9)

format long

vals(1)

ans =

2.620938226982966e-06

vals(1)=vals(1)*sqrt(2*pi*mi)/(e^1.5*Area*100^3);

vals(1)

ans =

5.507330928625227e+10

vals(2)

ans =

9.902502214206862

0 个评论

显示 -2更早的评论隐藏 -2更早的评论

请先登录,再进行评论。

请先登录,再回答此问题。

另请参阅

类别

Mathematics and OptimizationSymbolic Math ToolboxMuPADMuPAD Language FundamentalsData TypesData StructuresCommon Operations

Help CenterFile Exchange 中查找有关 Common Operations 的更多信息

标签

  • curve fitting

产品

  • MATLAB

版本

R2023a

Community Treasure Hunt

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

Start Hunting!

发生错误

由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。


Translated by lsqcurvefit issues due to variables being several orders of magnitu... (10)

lsqcurvefit issues due to variables being several orders of magnitu... (11)

选择网站

选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:

您也可以从以下列表中选择网站:

美洲

欧洲

亚太

联系您当地的办事处

lsqcurvefit issues due to variables being several orders of magnitu... (2024)
Top Articles
Follow Flight WN478 from Las Vegas, NV to Burbank, CA on AirNav RadarBox
Alex Cora's Yankees Jab Backfires, Fans Call Out 'Cheater' Red Sox Manager
Spasa Parish
Rentals for rent in Maastricht
159R Bus Schedule Pdf
Sallisaw Bin Store
Black Adam Showtimes Near Maya Cinemas Delano
Espn Transfer Portal Basketball
Pollen Levels Richmond
11 Best Sites Like The Chive For Funny Pictures and Memes
Things to do in Wichita Falls on weekends 12-15 September
Craigslist Pets Huntsville Alabama
Paulette Goddard | American Actress, Modern Times, Charlie Chaplin
Red Dead Redemption 2 Legendary Fish Locations Guide (“A Fisher of Fish”)
What's the Difference Between Halal and Haram Meat & Food?
R/Skinwalker
Rugged Gentleman Barber Shop Martinsburg Wv
Jennifer Lenzini Leaving Ktiv
Justified - Streams, Episodenguide und News zur Serie
Epay. Medstarhealth.org
Olde Kegg Bar & Grill Portage Menu
Cubilabras
Half Inning In Which The Home Team Bats Crossword
Amazing Lash Bay Colony
Juego Friv Poki
Ice Dodo Unblocked 76
Is Slatt Offensive
Labcorp Locations Near Me
Storm Prediction Center Convective Outlook
Experience the Convenience of Po Box 790010 St Louis Mo
Fungal Symbiote Terraria
modelo julia - PLAYBOARD
Poker News Views Gossip
Abby's Caribbean Cafe
Joanna Gaines Reveals Who Bought the 'Fixer Upper' Lake House and Her Favorite Features of the Milestone Project
Tri-State Dog Racing Results
Navy Qrs Supervisor Answers
Trade Chart Dave Richard
Lincoln Financial Field Section 110
Free Stuff Craigslist Roanoke Va
Wi Dept Of Regulation & Licensing
Pick N Pull Near Me [Locator Map + Guide + FAQ]
Crystal Westbrooks Nipple
Ice Hockey Dboard
Über 60 Prozent Rabatt auf E-Bikes: Aldi reduziert sämtliche Pedelecs stark im Preis - nur noch für kurze Zeit
Wie blocke ich einen Bot aus Boardman/USA - sellerforum.de
Infinity Pool Showtimes Near Maya Cinemas Bakersfield
Dermpathdiagnostics Com Pay Invoice
How To Use Price Chopper Points At Quiktrip
Maria Butina Bikini
Busted Newspaper Zapata Tx
Latest Posts
Article information

Author: Sen. Emmett Berge

Last Updated:

Views: 6315

Rating: 5 / 5 (80 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Sen. Emmett Berge

Birthday: 1993-06-17

Address: 787 Elvis Divide, Port Brice, OH 24507-6802

Phone: +9779049645255

Job: Senior Healthcare Specialist

Hobby: Cycling, Model building, Kitesurfing, Origami, Lapidary, Dance, Basketball

Introduction: My name is Sen. Emmett Berge, I am a funny, vast, charming, courageous, enthusiastic, jolly, famous person who loves writing and wants to share my knowledge and understanding with you.