How do I fit a curve with a custom equation and a loop?

1 次查看(过去 30 天)
I want to make a loop for a scatterplot and for each loop I want to do the fit curving to the plot with a custom equation. The equation for the scatterplot looks like this:
i_vals = [1 8 9 10]
j_vals = 1:10
for i = 1:length(i_vals)
for j = 1:length(j_vals)
scatter(eave(j, i_vals(i)), epsilonacc(j,i_vals(i)) ./ f_ampl(i_vals(i)), "sk")
hold on
end
end
hold off
title("Alle Proben bei N = 100")
xlabel("Porenzahl e")
ylabel("\epsilon^{acc} / f_{ampl}")
%legend
clear ('i_vals')
[1 8 9 10] - these are four samples
1:10 - ten rows per sample (representing N=10, N=100, N=500 ... N=100.000)
The scatter plot that you get from my code looks like this:
Each loop creates four points in a horizontal way. It should create something similar to this one (source: T. Wichtmann, A. Niemunis, Th. Triantafyllidis):
The function I want to use for the curve fitting ist the following:
f = kn .* ( (Ce - e).^2 ./ '(1 + e) )
Ce being a constant, e being a variable and kn being a constant which won't be used later.
If it doesn't work for this big amount of loops, than individual takes are also possible. At the end I need to get an average value of all the fitting curves to determine a constant.

采纳的回答

Star Strider
Star Strider 2022-7-16
The posted code needs the required variables and functions necessary to run it.
That aside, trysoimething like this —
a = linspace(0, atan(0.75/0.62), 7); % Create Missing Data
r = [0.52; 0.56; 0.62; 0.66]+0.1; % Create Missing Data
r = logspace(log10(0.52), log10(0.66), 7).'; % Create Missing Data
emx = r*cos(a); % Create Missing Data
emy = r*sin(a)+0.1; % Create Missing Data
f = @(kn,Ce,e) kn .* ( (Ce - e).^2 ./ (1 + e) );
b0 = randi(9,2,1) % Choose Appropriate Initial Parameter Estimates
b0 = 2×1
5 6
for k = 1:numel(a)
B(:,k) = fminsearch(@(b)norm(emy(:,k) - f(b(1),b(2),emx(:,k))), b0);
end
Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 0.000812
figure
plot(emx, emy, 's')
hold on
emxv = linspace(min(emx(:)), max(emx(:)), 50);
emxv = linspace(0, max(emx(:)), 50);
for k = 1:numel(a)
plot(emxv, f(B(1,k),B(2,k),emxv))
end
hold off
grid
There appears to be more to this than was posted, however this should get you started.
.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Scatter Plots 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by