matlab程序出错,请各位帮找一下原因format compactx=linspace(-2,8);f=x.^5-4*x.^4+3*x.^2-2*x+6+x.*sin(x);y1=zeros(size(x));plot(x,f)hold onplot(x,y1,'r')x1=solve('x^5-4*x^4+3*x^2-2*x+6+x*sin(x)','x')text(x1,0,'1.42688')运行后:x1 =1.4268
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/19 20:23:17
matlab程序出错,请各位帮找一下原因format compactx=linspace(-2,8);f=x.^5-4*x.^4+3*x.^2-2*x+6+x.*sin(x);y1=zeros(size(x));plot(x,f)hold onplot(x,y1,'r')x1=solve('x^5-4*x^4+3*x^2-2*x+6+x*sin(x)','x')text(x1,0,'1.42688')运行后:x1 =1.4268
matlab程序出错,请各位帮找一下原因
format compact
x=linspace(-2,8);
f=x.^5-4*x.^4+3*x.^2-2*x+6+x.*sin(x);
y1=zeros(size(x));
plot(x,f)
hold on
plot(x,y1,'r')
x1=solve('x^5-4*x^4+3*x^2-2*x+6+x*sin(x)','x')
text(x1,0,'1.42688')
运行后:
x1 =
1.426886968350643228428394466109
Error using text
Invalid parameter/value pair arguments
Error in main822 (line 9)
text(x1,0,'1.42688')
matlab程序出错,请各位帮找一下原因format compactx=linspace(-2,8);f=x.^5-4*x.^4+3*x.^2-2*x+6+x.*sin(x);y1=zeros(size(x));plot(x,f)hold onplot(x,y1,'r')x1=solve('x^5-4*x^4+3*x^2-2*x+6+x*sin(x)','x')text(x1,0,'1.42688')运行后:x1 =1.4268
x解出来竟然还是个复数,你x是符号型的,直接text会出错,为什么不用数值解呢,而且你都知道解释1.42688了,何必多此一举呢,顺便说一下,更精确的解是1.42689
x=linspace(-2,8);
f=x.^5-4*x.^4+3*x.^2-2*x+6+x.*sin(x);
y1=zeros(size(x));
plot(x,f)
hold on
plot(x,y1,'r')
x1=fsolve(@(x)x.^5-4*x.^4+3*x.^2-2*x+6+x.*sin(x),1)
text(x1,0,num2str(x1,6))