Output doesn't display a value, just an empty space.

2 次查看(过去 30 天)
So, I've got 2 pulses (imp and S0) and their sum (Si). I've got to find minimum of sum (Si). And I approximate the sum with a polynome. I took derivatives (1-st and 2-nd order) of the sum and polynome.
I analyze derivatives, and decided to look for minimum of sum (Si), polynome and 2-nd derivatives.
But, in some cases the result is just empty, but size of variable is 1x999 double.
lb = -5;
ub = 15;
x_imp = linspace(lb, ub, 1001);
x = linspace(lb, ub, 1001);
imp = sech(x_imp);
S0 = sech(x-10);
imp1 = sech(x - 1);
S1 = 0.5 * (imp1 + S0);
xmin = -1;
xmax = 10;
% find inflection point Si
range_x = x(x>=xmin & x<=xmax);
range_S1 = S1(x>=xmin & x<=xmax);
MinPtsS1 = islocalmin(range_S1);
fprintf ('x_S1 = %f , y_S1 = %f .\n', range_x(MinPtsS1), range_S1(MinPtsS1));
% polynom approximation pv
[p_S1, ~, mu] = polyfit(x, S1, 26);
pv_S1 = polyval (p_S1, x, [], mu);
% find inflection point of polynom pv
range_x = x(x>=xmin & x<=xmax);
range_pvS1 = pv_S1(x>=xmin & x<=xmax);
MinPts_pvS1 = islocalmin(range_pvS1);
fprintf('x_pvS1 = %f , y_pvS1 = %f .\n', range_x(MinPts_pvS1), range_pvS1(MinPts_pvS1));
% DIFF find inflection of diff2 Si, corresponding to inflection point of Si
dS1 = 20*diff (S1);
d2S1 = 10*diff(dS1);
range_x = x(x>=xmin & x<=xmin);
range_d2S1 = d2S1(x>=xmin & x<=xmin);
MinPts_d2S1 = islocalmin(range_d2S1);
fprintf('x_d2S1 = %f , y_d2S1 = %f .\n', range_x(MinPts_d2S1), range_d2S1(MinPts_d2S1));
% DIFF find inflection of diff2 polynom Si, corresponding to inflection point of Si
dpS1 = 20*diff(pv_S1);
dp2S1 = 20*diff(dpS1);
range_x = x(x>=xmin & x<=xmax);
range_dp2S1 = dp2S1(x>=xmin & x<=xmax);
MinPts_dp2S1 = islocalmin(range_dp2S1);
fprintf('x_dp2S1 = %f , y_dp2S1 = %f .\n', range_x(MinPts_dp2S1), range_dp2S1(MinPts_dp2S1));

采纳的回答

Stephen23
Stephen23 2025-7-16
编辑:Stephen23 2025-7-16
How many values fulfill your logical comparisons? Exactly one.
range_x = x(x>=xmin & x<=xmin);
range_d2S1 = d2S1(x>=xmin & x<=xmin);
should be
range_x = x(x>=xmin & x<=xmax);
range_d2S1 = d2S1(x>=xmin & x<=xmax);
Due to FPRINTF processing all input arguments in linear order you will also need to modify the FPRINTF input arguments (e.g. by defining a matrix), or use e.g. COMPOSE with column vectors.
There might be other bugs too...
  10 个评论
Stephen23
Stephen23 2025-7-17
编辑:Stephen23 2025-7-17
"... I need the min point of polynomial, around x = 5, which is not presented in all 4 methods.. "
X = linspace(-5, 15, 1001);
Y = 0.5 * (sech(X-1) + sech(X-10));
[p_S1, ~, mu] = polyfit(X, Y, 26);
pv_S1 = polyval(p_S1, X, [], mu);
dp_S1 = polyder(p_S1);
dpoly = @(xq) polyval(dp_S1, (xq-mu(1))./mu(2));
x_min = fzero(dpoly, 5)
x_min = 5.5017
y_min = interp1(X,Y,x_min)
y_min = 0.0222
Anna_P
Anna_P 2025-7-17
@Stephen23 THANK YOU!)
I'm not desperate anymore! Going to explore and study HELP section with more clarity now!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by