フィルターのクリア

please review matlab code and tell me why i receive errors

1 回表示 (過去 30 日間)
lateef
lateef 2023 年 7 月 21 日
回答済み: Image Analyst 2023 年 7 月 21 日
function [x_max, J_max] = maxperf(p, q)
% Define the polynomials p(x) and q(x)
P = polyval(p, x);
Q = polyval(q, x);
% Compute the objective function J(x)
J = P^2*Q;
% Find the roots of the derivative of J(x)
x_roots = roots(polyder(J));
% Filter out roots that are not finite and real
x_roots = x_roots(isfinite(x_roots) & isreal(x_roots));
% Evaluate J(x) at each root
J_vals = polyval(J, x_roots);
% Find the index of the root that produces the maximum J(x)
[J_max, index] = max(J_vals);
% Find the corresponding x that maximizes J(x)
x_max = x_roots(index);
% Display the result
disp(['The maximum value of x is: ', num2str(x_max)]);
disp(['The corresponding maximal value of J is: ', num2str(J_max)]);
end
i defined functions p and q and still get an error in the code

回答 (1 件)

Image Analyst
Image Analyst 2023 年 7 月 21 日
p and q are not functions. They are input arguments. What did you assign for them, and how did you call maxperf()? For example did you do
p = polyfit(x1, y1, 2);
q = polyfit(x2, y2, 2);
[x_max, J_max] = maxperf(p, q)
And since you use x inside maxperf() it needs to be assigned. Please show us the missing code where you assigned x, either by passing in x, or assigning x to some array in maxperf.

カテゴリ

Help Center および File ExchangeScope Variables and Generate Names についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by