用函数roots求方程x^2-x-1=0的根在matlab中
时间: 2024-04-30 08:18:40 浏览: 202
在Matlab中,可以使用roots函数求解二次方程的根。具体步骤如下:
1. 将二次方程的系数存储在一个向量中,例如:coeff = [1 -1 -1],其中1表示x的二次项系数,-1表示x的一次项系数,-1表示常数项系数。
2. 调用roots函数,传入系数向量作为参数,例如:roots(coeff)。
3. 函数将返回一个向量,包含方程的两个根。如果方程没有实数根,则返回两个虚数根。
完整的代码如下:
```matlab
coeff = [1 -1 -1];
roots(coeff);
```
输出结果为:
```
ans =
1.6180
-0.6180
```
这表明方程x^2-x-1=0的两个实数根分别为1.6180和-0.6180。
相关问题
求方程2x^5-3x^3+71x^2-9x+13=0的根用matlab解决
可以使用MATLAB的解方程函数`roots`来解这个方程。首先,我们需要将方程转化为向量形式:
```
coefficients = [2, -3, 71, -9, 13];
```
然后,我们可以使用`roots`函数来解这个方程:
```
roots(coefficients)
```
这将返回一个包含方程的根的向量。注意,这个方程可能有复数根,因为它是一个五次方程。如果需要,可以使用`real`和`imag`函数来分别获取实部和虚部。
完整的MATLAB代码如下:
```
coefficients = [2, -3, 71, -9, 13];
roots(coefficients)
```
用MATLAB求方程 2X^5-3X^3+71X^2-9X+13=0的 全部根。
可以使用MATLAB中的`roots`函数求解该方程的所有根。具体操作如下:
1. 将方程的系数存储在一个向量中:
```
coeff = [2, -3, 71, -9, 13];
```
2. 使用`roots`函数求解该方程的所有根:
```
roots(coeff)
```
运行后,MATLAB会输出该方程的所有根。
阅读全文
相关推荐












