Multiplying f(x) with f(-x)

3 ビュー (過去 30 日間)
Omar Decevic
Omar Decevic 2022 年 4 月 23 日
編集済み: Bruno Luong 2022 年 4 月 23 日
I need to write a code that will multiply function f(x) with f(-x)
Function is always inputed by user in form of an array.
coefficients = input('Enter the coefficients of the function with [ ] around them');
example: If user inputs [1 15 7 2] I would want to mutliply with .
Is there any way for this to be doen without writting a tone of code?
Thank you

採用された回答

VBBV
VBBV 2022 年 4 月 23 日
編集済み: VBBV 2022 年 4 月 23 日
cof = [1 15 7 2]
cof = 1×4
1 15 7 2
syms x F(x)
F = (cof(1)*x.^3+cof(2)*x.^2+cof(3)*x+cof(4))
F = 
FF = subs(F,x,-x)
FF = 
Fx = F.*FF % resulting product
Fx = 
Fx = simplify(Fx)
Fx = 
  1 件のコメント
Omar Decevic
Omar Decevic 2022 年 4 月 23 日
Thank you!

サインインしてコメントする。

その他の回答 (2 件)

Sam Chak
Sam Chak 2022 年 4 月 23 日
You can try this and take over from here:
x = -16:0.01:16;
f = @(x) x.^3 + 15*x.^2 + 7*x + 2;
plot(x, f(x).*f(-x), 'linewidth', 1.5)
grid on
xlabel('x')
ylabel('y')
title('f(x)*f(-x)')

Bruno Luong
Bruno Luong 2022 年 4 月 23 日
編集済み: Bruno Luong 2022 年 4 月 23 日
For polynomial funtions with coefficients in P, f(x)*f(-x) is a polynomial as well with coefficients Q that can be computed like this
P=[1 15 7 2];
Pm=P.*(-1).^(length(P)-1:-1:0);
Q=conv(P,Pm)
Q = 1×7
-1 0 211 0 11 0 4
hold on; ezplot(@(x)polyval(P,x).*polyval(P,-x)); ezplot(@(x)polyval(Q,x));

カテゴリ

Help Center および File ExchangePolynomials についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by