matlab符号与数值转换

上传人:wm****3 文档编号:43080431 上传时间:2018-06-04 格式:DOC 页数:25 大小:20.42KB
返回 下载 相关 举报
matlab符号与数值转换_第1页
第1页 / 共25页
matlab符号与数值转换_第2页
第2页 / 共25页
matlab符号与数值转换_第3页
第3页 / 共25页
matlab符号与数值转换_第4页
第4页 / 共25页
matlab符号与数值转换_第5页
第5页 / 共25页
点击查看更多>>
资源描述

《matlab符号与数值转换》由会员分享,可在线阅读,更多相关《matlab符号与数值转换(25页珍藏版)》请在金锄头文库上搜索。

1、matlabmatlab 符号与数值转换符号与数值转换a=1/3;format rat;a结果果然是 a=1/3 rats(a)一旦创建了一个符号表达式,或许想以某些方式改变它;也许希望提取表达式的一部分,合并两个表达式或求得表达的数值。有许多符号工具可以帮助完成这些任务。 所有符号函数(很少特殊例外的情况,讨论于后)作用到符号表达式和符号数组,并返回符号表达式或数组。其结果有时可能看起来象一个数字,但事实上它是一个内部用字符串表示的一个符号表达式。正如我们前面所讨论的,可以运用 MATLAB 函数 isstr 来找出像似数字的表达式是否真是一个整数或是一个字符串。提取分子和分母如果表达式是一

2、个有理分式(两个多项式之比),或是可以展开为有理分式(包括哪些分母为 1 的分式),可利用 numden 来提取分子或分母。例如,给定如下的表达式:在必要时,numden 将表达式合并、有理化并返回所得的分子和分母。进行这项运算的 MATLAB 语句是:view plaincopy to clipboardprint? m= x2 % create a simple expression m= x2 n,d=numden(m) % extract the numerator and denominator n= x2 d= 1 f= a*x2/(b-x) % create a rational

3、 expression f= a*x2/(b-x) n,d=numden(f) % extract the numerator and denominator n= a*x2 d= b-x m= x2 % create a simple expressionm=x2 n,d=numden(m) % extract the numerator and denominatorn=x2d=1 f= a*x2/(b-x) % create a rational expressionf=a*x2/(b-x) n,d=numden(f) % extract the numerator and denomi

4、natorn=a*x2d=b-x前二个表达式得到期望结果。view plaincopy to clipboardprint? g= 3/2*x2+2/3*x-3/5 % rationalize and extract the parts g= 3/2*x2+2/3*x-3/5 n,d=numden(g) n= 45*x2+20*x-18 d= 30 h= (x2+3)/(2*x-1)+3*x/(x-1) % the sum of rational polynomials h= (x2+3)/(2*x-1)+3*x/(x-1) n,d=numden(h) % rationalize and ex

5、tract n= x3+5*x2-3 d= (2*x-1)*(x-1) g= 3/2*x2+2/3*x-3/5 % rationalize and extract the partsg=3/2*x2+2/3*x-3/5 n,d=numden(g)n=45*x2+20*x-18d=30 h= (x2+3)/(2*x-1)+3*x/(x-1) % the sum of rational polynomialsh=(x2+3)/(2*x-1)+3*x/(x-1) n,d=numden(h) % rationalize and extractn=x3+5*x2-3d=(2*x-1)*(x-1) 在提取

6、各部分之前,这二个表达式 g 和 h 被有理化,并变换成具有分子和分母的一个简单表达式。view plaincopy to clipboardprint? k=“sym“( 3/2,(2*x+1)/3;4/x2,3*x+4 ) % try a symbolic array k= 3/2,(2*x+1)/3 4/x2, 3*x+4 n,d=numden(k) n= 3, 2*x+1 4, 3*x+4 d= 2,3 x2,1 k=“sym“( 3/2,(2*x+1)/3;4/x2,3*x+4 ) % try a symbolic arrayk= 3/2,(2*x+1)/34/x2, 3*x+4 n

7、,d=numden(k)n=3, 2*x+14, 3*x+4d= 2,3x2,1 这个表达式 k 是符号数组,numden 返回两个新数组 n 和 d,其中 n 是分子数组,d 是分母数组。如果采用 s=numden(f)形式,numden 仅把分子返回到变量 s 中。标准代数运算很多标准的代数运算可以在符号表达式上执行,函数symadd、symsub、symlnul 和 symdiv 为加、减、乘、除两个表达式,sympow 将一个表达式上升为另一个表达式的幂次(MATLAB 7.中不可用) 。例如: 给定两个函数view plaincopy to clipboardprint? f= 2*

8、x2+3*x-5 % define the symbolic expression f= 2*x2+3*x-5 g= x2-x+7 g= x2-x+7 symadd(f,g) % find an expression for f+g ans= 3*x2+2*x+2 symsub(f,g) % find an expression for f-g ans= x2+4*x-12 symmul(f,g) % find an expression for f*g ans= (2*x2+3*x-5)*(x2-x+7) symdiv(f,g) % find an expression for f/g an

9、s= (2*x2+3*x-5)/(x2-x+7) sympow(f, 3*x ) % find an expression for ans= (2*x2+3*x-5)3* f= 2*x2+3*x-5 % define the symbolic expressionf=2*x2+3*x-5 g= x2-x+7 g=x2-x+7 symadd(f,g) % find an expression for f+gans=3*x2+2*x+2 symsub(f,g) % find an expression for f-gans=x2+4*x-12 symmul(f,g) % find an expre

10、ssion for f*gans=(2*x2+3*x-5)*(x2-x+7) symdiv(f,g) % find an expression for f/gans=(2*x2+3*x-5)/(x2-x+7) sympow(f, 3*x ) % find an expression for ans=(2*x2+3*x-5)3* 另一个通用函数可让用户用其它的符号变量、表达式和算子创建新的表达式。symop 取由逗号隔开的、多至 16 个参量。各个参量可为符号表达式、数值或算子( + 、 - 、*、 / 、 、 ( 或 ) ),然后 symop 可将参量联接起来,返回最后所得的表达式.view

11、plaincopy to clipboardprint? f= cos(x) % create an expression f= cos(x) g= sin(2*x) % create another expression g= sin(2*x) symop(f,/ ,g,+,3) % combine them ans= cos(x)/sin(2*x)+3 f= cos(x) % create an expressionf=cos(x) g= sin(2*x) % create another expressiong=sin(2*x) symop(f,/ ,g,+,3) % combine t

12、hemans=cos(x)/sin(2*x)+3 所有这些运算也同样用数组参量进行。高级运算MATLAB 具有对符号表达式执行更高级运算的功能。函数compose 把 f(x)和 g(x)复合成 f(g(x)。函数 finverse 求表达式的函数逆,而函数 symsum 求表达式的符号和。给定表达式view plaincopy to clipboardprint? f= 1/(1+x2) ; % create the four expression g= sin(x) ; h= 1/(1+u2) ; k= sin(v) ; compose(f,g) % find an expression

13、for f(g(x) ans= 1/(1+sin(x)2) compose(g,f) % find an expression for g(f(x) ans= sin(1/(1+x2) f= 1/(1+x2) ; % create the four expression g= sin(x) ; h= 1/(1+u2) ; k= sin(v) ; compose(f,g) % find an expression for f(g(x)ans=1/(1+sin(x)2) compose(g,f) % find an expression for g(f(x)ans=sin(1/(1+x2) com

14、pose 也可用于含有不同独立变量的函数表达式。view plaincopy to clipboardprint? compose(h,k,u,v) % given h(u),k(v),find(k(v) ans= 1/(1+sin(v)2) compose(h,k,u,v) % given h(u),k(v),find(k(v)ans=1/(1+sin(v)2) 表达式譬如 f(x)的函数逆 g(x),满足 g(f(x)=x。例如, 的函数逆是 ln(x),因为 ln( )=x。sin(x)的函数逆是 arcsin(x),函数 的函数逆是 arcsin 。函数 fincerse 返回表达式的函数逆。如果解不是唯一就给出警告。view plaincopy to clipboardprint? finverse( 1/x) % the inverse of 1/x is 1/x since 1/(1/x)=x ans= 1/x finverse( x2 ) % g(x2)=x has more than one solution Warning: finverse(x2) is not unique

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 社会民生

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号