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

4 vues (au cours des 30 derniers jours)
Almas Adil
Almas Adil le 7 Juin 2018
Commenté : Almas Adil le 8 Juin 2018
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".

Réponse acceptée

Steven Lord
Steven Lord le 7 Juin 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.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB Coder dans Help Center et File Exchange

Produits


Version

R12.1

Community Treasure Hunt

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

Start Hunting!

Translated by