plotting a polynomial problem

1 view (last 30 days)
vaggelis vaggelakis
vaggelis vaggelakis on 28 Nov 2012
hello everyone!
maybe it's too simple, but i got a little angry trying to plot a polynomial
let's say : u=a*x+b*x^2+c*x^3+d*x^4 and x=0:0.01:1 when i try to evaluate u the red message says
Error using ==> mpower Matrix must be square.
i had no problem plotting another function like f=a-b*exp(4*x)+c*x
why does the error come up?
(i found something for "polyval" function but how do i use it when i have only x multipliers?)
I can evaluate the polynomial when x has a single value and it is not an array

Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 28 Nov 2012
Edited: Azzi Abdelmalek on 28 Nov 2012
use operations element by element .^
x=0:0.01:1
u=a*x+b*x.^2+c*x.^3+d*x.^4
because x is a vector, to compute x^2, x must be square. So you can use
[2 4 6].^2=[2^2 4^2 6^2]

Categories

Find more on Polynomials in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!