matlab-代数方程

solve求解简单代数方程:

>> syms x;
>> quea=x+2==0;
>> x=solve(quea)
 
x =
 
-2

求解二次方程

>> syms x;
que=x^2-6*x+10==0;
solve(que)
 
ans =
 
3 - 1i
3 + 1i
 

>> s=solve(que)
 
s =
 
3 - 1i
3 + 1i

这两个根分别存在s(1)和s(2)中。

>> y=s(1)+3
 
y =
 
6 - 1i

symbolic:符号

detour:绕行

ezplot:绘制符号曲线

ezplot:方便的为顶部显示的绘图生成了标题并为我们标注了x轴

>> syms x
>> d='x^2-7*x+10';
>> ezplot(d)

 ezplot(f,[x_{1},x_{2}]):给自变量选取一个变化范围并绘图

ezplot(d,[-2,10])
 

ezplot(z,[x1,x2,y1,y2])

>> y=x+3;
>> ezplot(y,[0,2,1,5])

>> q=x^2+x-sqrt(2);
>> x=solve(q)
 
x =
 
- (4*2^(1/2) + 1)^(1/2)/2 - 1/2
  (4*2^(1/2) + 1)^(1/2)/2 - 1/2

>> ezplot(q)

 为了确定x1和x2的数值,需要将其转换为double类型。

>> z=double(x(1))

z =

         -1.79

>> s=double(x(2))

s =

          0.79

求解高阶方程:

>> syms x;
>> q=(x+1).^2*(x-2);
>> solve(q)
 
ans =
 
-1
-1
 2

>>  
syms  x;
q=x^4-5*x^3+4*x^2-5*x+6;
x=solve(q)
 
 
x =
 
root(z^4 - 5*z^3 + 4*z^2 - 5*z + 6, z, 1)
root(z^4 - 5*z^3 + 4*z^2 - 5*z + 6, z, 2)
root(z^4 - 5*z^3 + 4*z^2 - 5*z + 6, z, 3)
root(z^4 - 5*z^3 + 4*z^2 - 5*z + 6, z, 4)
 
>> i1=double(x(1))

i1 =

          1.12

>> i2=double(x(2))

i2 =

         -0.19

>> i3=double(x(3))

i3 =

         -0.19

>> i4=double(x(4))

i4 =

          4.26

>> ezplot(q,[-10,10])

 ?????不应该是虚根吗???

工作区里面i2和i3是虚根,在显示的时候只显示了根的实部。

>> syms x;
>> q=x^3+3*x^2-2*x-6;
>> solve(q)
 
ans =
 
      -3
 2^(1/2)
-2^(1/2)
 
>> ezplot(q,[-8,8,-8,8])

求解方程组:

  依然用solve求解,此时要注意方程写的 方法

>> syms x y;
q=[5*x+4*y==3,x-6*y==2];
s=solve(q)

s = 

  包含以下字段的 struct:

    x: [1×1 sym]
    y: [1×1 sym]

>> s.x
 
ans =
 
13/17
 
>> s.y
 
ans =
 
-7/34

用solve求解更大的线性方程组:

>> syms w x y z;
>> q=[w+x+4*y+3*z==5,2*w+3*x+y-2*z==1,w+2*x-5*y+4*z==3,w-3*z==9];
>> s=solve(q)

s = 

  包含以下字段的 struct:

    w: [1×1 sym]
    x: [1×1 sym]
    y: [1×1 sym]
    z: [1×1 sym]

>> s.w
 
ans =
 
1404/127
 
>> s.x
 
ans =
 
-818/127
 
>> s.y
 
ans =
 
-53/127
 
>> s.z
 
ans =
 
87/127

方程的展开与合并

展开:expand

>> expand((x-2)*(x-5))
 
ans =
 
x^2 - 7*x + 10


>> expand(cos(x+y))
 
ans =
 
cos(x)*cos(y) - sin(x)*sin(y)

要使用新的符号时,必须要先对该符号定义:syms 

>> expand((y-1)*(y-8))
函数或变量 'y' 无法识别。
 
>> syms y;
>> expand((y-1)*(y-8))
 
ans =
 
y^2 - 9*y + 8

collect:与expand作用相似

>> syms x;
>> collect(x*(x^2-2))
 
ans =
 
x^3 - 2*x

>> expand((x*(x^2-2)))
 
ans =
 
x^3 - 2*x

>> syms t;
>> collect((x+3)*sin(t))
 
ans =
 
sin(t)*x + 3*sin(t)
 
>> expand((x+3)*sin(t))
 
ans =
 
3*sin(t) + x*sin(t)

factor:因式分解

>> factor((x^2-y^2))
 
ans =
 
[x - y, x + y]

simplify:用于多项式的除法

>> simplify((x^4-81)/(x^2-9))
 
ans =
 
x^2 + 9

>> simplify(exp(2*log(3*x)))
 
ans =
 
9*x^2

>> simplify(cos(x)^2-sin(x)^2)
 
ans =
 
cos(2*x)

求解指数函数(exponential functions)和对数函数(log functions)

同样用solve求解

>> syms x;
>> q=(log10(x)-log10(x-3)==1);
>> solve(q)
 
ans =
 
10/3

>> syms y
 q=[y==3^(2*x),y==5^x+1];
s=solve(q)
警告: Unable to solve symbolically. Returning a numeric solution
using vpasolve. 
> 位置:sym/solve (第 304 行) 

s = 

  包含以下字段的 struct:

    x: [1×1 sym]
    y: [1×1 sym]

>> s.x
 
ans =
 
0.57107246071180090433600366899982
 
>> s.y
 
ans =
 
3.5070472569953984356582573486301

函数的级数表达

taylor(function):对函数进行泰勒级数展开

>> syms x;
>> s=taylor(sin(x))
 
s =
 
x^5/120 - x^3/6 + x

 
>> ezplot(s)

 taylor(function,x,'Order',n):对函数进行泰勒级数展开至第n项

s=taylor(sin(x),x,'Order',20)
 
s =
 
- x^19/121645100408832000 + x^17/355687428096000 - x^15/1307674368000 + x^13/6227020800 - x^11/39916800 + x^9/362880 - x^7/5040 + x^5/120 - x^3/6 + x

>> ezplot(s)

 

>> x=7*sqrt(2)-5*sqrt(60)+5*sqrt(8)

x =

  -14.6882

>> syms x;
>> q=(3*x^2+2*x==7);
>> s=solve(q)
 
s =
 
- 22^(1/2)/3 - 1/3
  22^(1/2)/3 - 1/3
 
>> d1=double(s(1))

d1 =

   -1.8968

>> d2=double(s(2))

d2 =

    1.2301
 

>> syms x;
>> q=(x^2+sqrt(5)*x-pi==0);
>> s=slove(q)
函数或变量 'slove' 无法识别。
 
是不是想输入:
>> s=solve(q)
 
s =
 
- 5^(1/2)/2 - (4*pi + 5)^(1/2)/2
  (4*pi + 5)^(1/2)/2 - 5^(1/2)/2
 
>> d1=double(s(1))

d1 =

   -3.2136

>> d2=double(s(2))

d2 =

    0.9776

>> q=(sqrt(2*x-4)-1);
ezplot(q,[2 4 0 1])

 

>> syms x y;
syms z;q=[x-3*y-2*z==6,2*x-4*y-3*z==8,-3*x+6*y+8*z==-5];
s=solve(q)

s = 

  包含以下字段的 struct:

    x: [1×1 sym]
    y: [1×1 sym]
    z: [1×1 sym]

>> s.x
 
ans =
 
1
 
>> s.y
 
ans =
 
-3
 
>> s.z
 
ans =
 
2

>> s=taylor(4/(5-cos(x)),x,'Order',10)
 
s =
 
(241*x^8)/258048 - (113*x^6)/23040 + (5*x^4)/192 - x^2/8 + 1
 
>> ezplot(s)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一夕ξ

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值