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 Center および File ExchangePolynomials についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by