fminsearch curve fitting HELP!!
4 ビュー (過去 30 日間)
古いコメントを表示
I'm very new to Matlab and working on a code based on Hoek-Brown failure Criteria. I'm trying to use fminsearch to estimate
m and s
from a set of sigma1 (s1) and sigma3 (s3) data points. I am estimating m and s parameters the others are contants. My code is as follows:
s1 = [7.04,12.8,16.47,25.61,39.14];
s3 = [0.0,1.5,3,5,10];
a = 0.5;
sc = 32.7;
m = 20; %initial values
s = 0.002; %initial values
plot(s3, s1, '+', 'MarkerSize', 10, 'LineWidth', 2)
pred = @(m,s) s3+(((m*s3/sc)+s).^a)*sc-sl;
sb=sum(pred.^2);
sumres=sb;
est=fminsearch(pred,[m s]);
m=est(l);
s=est(2);
0 件のコメント
採用された回答
Star Strider
2021 年 3 月 18 日
I am not certain what you are doing.
This runs without error, however I have no idea what the correct result should be, or how to plot the fitted result.
Try this:
s1 = [7.04,12.8,16.47,25.61,39.14];
s3 = [0.0,1.5,3,5,10];
a = 0.5;
sc = 32.7;
m = 20; %initial values
s = 0.002; %initial values
% plot(s3, s1, '+', 'MarkerSize', 10, 'LineWidth', 2)
% pred = @([m,s]) s3+(((m*s3/sc)+s).^a)*sc-s1;
pred = @(b) s3+(((b(1)*s3/sc)+b(2)).^a)*sc-s1;
sb=@(b)norm(pred(b));
sumres=sb;
est=fminsearch(sb,[m s]);
m=est(1);
s=est(2);
figure
plot(s3, s1, '+', 'MarkerSize', 10, 'LineWidth', 2)
hold on
plot(s3, pred(est), '-r')
hold off
grid
.
2 件のコメント
Star Strider
2021 年 3 月 18 日
The function should produce an estimate of the dependent variable as a funciton of the intdependent variable. The problem is that I cannot figure out what the actual expression is.
その他の回答 (1 件)
John D'Errico
2021 年 3 月 18 日
編集済み: John D'Errico
2021 年 3 月 18 日
- You use sl in places in your code, yet you never defined sl. Yes, that is a lower case L, not the number 1. My guess is you meant to write s1, where that is the number 1.
- You seem to think that having indented the computation of sb and sumres in there, they will be used in the call to fminsearch. WRONG.
- While you call fminsearch properly with a VECTOR of length 2, you defined your function to take TWO arguments. WRONG. pred must also take a vector argument, of length 2. Like this (Note I changed the sl to an s1):
sumres = @(ms) sum(s3+(((ms(1)*s3/sc)+ms(2)).^a)*sc-s1).^2;
As written there, the function sumres will return a residual sum of squares. Call it with fminsearch, and you might have some chance.
Finally, your data hardly seems to support that model, with effectively a sqrt in it, since a = 0.5. Your data lies in a straight line, lacking any curvature at all.
s1 = [7.04,12.8,16.47,25.61,39.14];
s3 = [0.0,1.5,3,5,10];
a = 0.5;
sc = 32.7;
m = 20; %initial values
s = 0.002; %initial values
plot(s3, s1, '+', 'MarkerSize', 10, 'LineWidth', 2)
All I see there is a straight line, with some noise in it, far more noise than you could use to estimate those parameters. And with only 5 data points, any estimate you did get out would be virtually meaningless junk.
Anyway, I'd suggest if you are doing a lot of curve fitting, you consider the curve fitting toolbox.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Interpolation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!