Basic Function Error (Plot Related

1 回表示 (過去 30 日間)
buxZED
buxZED 2011 年 2 月 23 日
y=f(x)=2.8x^3 - 3.5x^2 + 1.5x - (0.15 + 0.1*0.2529)=0
Plot this function (x in the range of [0, 1])
this is the given question following is my attempt
>> x=linspace(0,1,200);%this is to generate values for "x"
>> y=(2.8*x^3)-(-3.5*x^2)+(1.5*x)-(0.15+(0.1*stu_id))
??? Error using ==> mpower
Matrix must be square.
>> y=(2.8*.x^3)-(-3.5*.x^2)+(1.5*.x)-(0.15+(0.1*stu_id))
??? y=(2.8*.x^3)-(-3.5*.x^2)+(1.5*.x)-(0.15+(0.1*stu_id))
|
Error: Unexpected MATLAB operator.
>> y=(2.8*.x^3)-(-3.5*.x^2)+(1.5*.x)-(0.15+(0.1*stu_id))=0
??? y=(2.8*.x^3)-(-3.5*.x^2)+(1.5*.x)-(0.15+(0.1*stu_id))=0
|
Error: Unexpected MATLAB operator.
>> 0=(2.8*.x^3)-(-3.5*.x^2)+(1.5*.x)-(0.15+(0.1*stu_id))
??? 0=(2.8*.x^3)-(-3.5*.x^2)+(1.5*.x)-(0.15+(0.1*stu_id))
|
Error: The expression to the left of the equals sign is not a
valid target for an assignment.
>>
much appreciate if anyone can point in the right direction

採用された回答

Davide Ferraro
Davide Ferraro 2011 年 2 月 23 日
You should use the element by element power elevation ".^". Without the "dot" you are trying to do the power of a matrix and this is defined only for a square matrix.
y=(2.8*x.^3)-(-3.5*x.^2)+(1.5*x)-(0.15+(0.1*stu_id))
This should work to evaluate the function (you need also to define the stu_id variable).
  1 件のコメント
buxZED
buxZED 2011 年 2 月 23 日
much appriciated :D

サインインしてコメントする。

その他の回答 (2 件)

Matt Tearle
Matt Tearle 2011 年 2 月 23 日
The operator you're looking for is .^ (ie x.^2)
And similarly .* and ./

Andrew Newell
Andrew Newell 2011 年 2 月 23 日
You've got the dot and the star in the wrong order, and you don't need the dot anyway for multiplying by a scalar. Try this:
y=(2.8*x.^3)-(-3.5*x.^2)+(1.5*x)-(0.15+(0.1*stu_id))

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by