using polyval(a,x)

1 次查看(过去 30 天)
Dwyane  Wade
Dwyane Wade 2011-8-15
Hi guys please help me I cant seem to figure out how to use polyval(a,x), I need to use it to solve the following problem:
1.) Confirm that 6x^3+4x^2-5/12x^3-7x^2+3x+9=0.7108 when x=2;
please help me. thanks

回答(2 个)

Sean de Wolski
Sean de Wolski 2011-8-15
It doesn't
fzero(@(x)6*x^3+4*x^2-5/12*x^3-7*x^2+3*x+8.2892,pi)

Paulo Silva
Paulo Silva 2011-8-15
%first way to find if the equality is correct
f=@(x) (-5/12+6)*x^3+(-7+4)*x^2+3*x+9;
f(2)
%second way
polyval([-5/12+6 -7+4 3 9],2)
%yet another way that only works if you have the symbolic toolbox
syms x
f=6*x^3+4*x^2-5/12*x^3-7*x^2+3*x+9;
subs(f,x,2)
every way gives the value 47.666666666666664 not 0.7108, so it's not confirmed, the assumption is wrong.
f=@(x) (-5/12+6)*x^3+(-7+4)*x^2+3*x+9;
ezplot(f,[0 4])
hold on
line(xlim,[0.7108 0.7108],'color',[1 0 0])
line([2 2],ylim,'color',[1 0 0])
plot(2,f(2),'o','linewidth',4,'markersize',10)
text(2,f(2),['\leftarrow' 'x=2 and y=' num2str(f(2))],'FontSize',18)
text(2,0.7108,['\leftarrow' 'x=2 and y=' '0.7108'],'FontSize',18)
  2 个评论
Sean de Wolski
Sean de Wolski 2011-8-15
And ezplot makes a pretty picture to confirm:
ezplot(f)
Paulo Silva
Paulo Silva 2011-8-15
yes it does :)

请先登录,再进行评论。

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by