i have an equation to solve y(x)=0.9x^4-12x^2)-5x.

4 views (last 30 days)
y(x)=0.9x^4-12x^2)-5x.
here is my matlab code
x=[-4:1:4];
y(x)=0.9*power((x),4)-12*power((x),2)-5*(x)
by running this i am getting error "Subscript indices must either be real positive integers or logicals".

Accepted Answer

Steven Lord
Steven Lord on 7 Jun 2018
When you type y(x) = ... like that, you're trying to assign to the -4th element of y. There's no such thing as the -4th element of an array in MATLAB, so you will receive that error when you ask for it.
If you want a vector of values of your polynomial evaluated at the values in the vector x, just assign to y not y(x).
x = -4:1:4;
y = (0.9*x.^4-12*x.^2)-5*x
If you want to find roots of your polynomial, you can create the vector of coefficients and use the roots function. The vector of coefficients has the coefficient of the highest power term as the first element, the constant term as the last element, and must have coefficients for each power of your variable between (even if they're 0.) Or you can write a function that evaluates your polynomial and call the fzero function.

More Answers (0)

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Products


Release

R12.1

Community Treasure Hunt

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

Start Hunting!