plotting a polynomial problem

1 次查看(过去 30 天)
vaggelis vaggelakis
vaggelis vaggelakis 2012-11-28
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

回答(1 个)

Azzi Abdelmalek
Azzi Abdelmalek 2012-11-28
编辑:Azzi Abdelmalek 2012-11-28
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]

类别

Help CenterFile Exchange 中查找有关 Polynomials 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by