# How to form an array from -10 to 10 to substitute into a polynomial as values of x and have the evaluated values as the output

1 回表示 (過去 30 日間)
Liam Wiltshire 2018 年 1 月 4 日
コメント済み: Liam Wiltshire 2018 年 1 月 4 日
My attempt is as follows:
function scriptStart
for x = (-10:10)
y = x.^3 - 3*x.^2 + 5*x*sin(pi(x/4) - 5*(pi/4)) + 3;
end
All I get as outputs is an error, which changes every time i try to make a change to the above.
Error using pi
Too many input arguments.
Error in scriptStart (line 4)
y = x.^3 - 3*x.^2 + 5*x*sin(pi(x/4) - 5*(pi/4)) + 3;
This is my current and mostr persistant error. I've looked and looked and i cant find the solution to my specific problem, presumably because it is so simple nobody has had to ask. So let me be the first.
I need to create an array for the x variable from x = −10 to x = 10, with appropriate spacing. Then use a for loop to evaluate the values of F according to equation
y = x^3 - 3*x^2 + 5*x*sin(pi(x/4) - 5*(pi/4)) + 3;
Any and all help appreciated,
Thank you

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

### 採用された回答

Birdman 2018 年 1 月 4 日
A symbolic approach(requires Symbolic Toolbox)
syms x
y = x.^3 - 3*x.^2 + 5*x*sin(pi*(x/4) - 5*(pi/4)) + 3;
yVal=vpa(subs(y,x,-10:10),4)
##### 1 件のコメント-1 件の古いコメントを表示-1 件の古いコメントを非表示
Liam Wiltshire 2018 年 1 月 4 日
Fab, thank you very much this worked a charm.

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

### カテゴリ

Help Center および File ExchangeFormula Manipulation and Simplification についてさらに検索

### Community Treasure Hunt

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

Start Hunting!

Translated by