第六章 MATLAB IN ENGINEERING

Polynomial Differentiation多项式微分

 %幂级数
 f(x) = x^3-2x-5;
 p = [1 0 -2 -5]  %自变量前系数
 ​
 polyval()
 eg:
 a = [9, -5, 3, 7];
 x = -2:0.01:5;
 f = polyval(a,x);  %表示a系数下的X处的微商数值
 plot(x,f,'LineWidth',2);
 xlabel('x');
 ylabel('f(x)');
 set(gca,'FontSize',14)
 ​
 polyder()  %给的是微商式子
 eg:
 p = [5 0 -2 0 1];
 polyder(p)    %微分符号
 eg:
 p = [5 0 -2 0 1];
 polyder(p);
 polyval(polyder(p),7)

Polynomial Integration多项式积分

 polyint()  %不定积分
 eg:
 p = [5 0 -2 0 1];
 polyint(p,3);    %积分后的常数项是3
 polyval(polyint(p,3),7)    %不定积分7处的积分值

Numerical Differentiation

 diff()    %计算前后差异  
 eg1:
 x = [1 2 5 2 1];
 diff(x)   % ans = [1 3 -3 -1];
 eg2(两点斜率(1,5),(2,7)):
 x = [1 2];
 y = [5 7];
 slope = diff(y)./diff(x)
 ​
 eg3:
 x0 = pi/2;
 h = 0.1;
 x = [x0 x0+h];
 y = [sin(x0) sin(x0+h)];
 m = diff(y)./diff(x)
 eg4:
 h = 0.5;
 x = 0:h:2*pi;
 y = sin(x);
 m = diff(y)./diff(x);
 //h的大小对于导函数的影响:
 g = colormap(lines);
 hold on;
 for i = 1:4
  x = 0:power(10,-i):pi;
  y = sin(x);
  m = diff(y)./diff(x);
  plot(x(1:end-1),m,'Color',g(i,:));
 end
 hold off;
 set(gca,'XLim',[0,pi/2]);
 set(gca,'YLim',[0,1.2]);
 set(gca,'FontSize',18);
 set(gca,'FontName','symbol');
 set(gca,'XTick',0:pi/4:pi/2);
 set(gca,'XTickLabel',{'0','p/4','p/2'});
 h = legend('h = 0.1','h = 0.01','h = 0.001','h = 0.0001');
 set(h,'FontName','Times New Roman');
 box on;

Second and Third Derivatives

 x = -2:0.005:2;
 y = x.^3;
 m = diff(y)./diff(x);
 m2 = diff(m)./diff(x(1:end-1));
 ​
 plot(x,y,x(1:end-1),m,x(1:end-2),m2);
 xlabel('x','FontSize',18);
 ylabel('y','FontSize',18);
 legend('f(x) = x^3','f''(x)','f''''(x)');
 set(gca, 'FontSize',18);

Numerical Integration

Midpoint Rule用矩形去逼近

 h = 0.05;
 x = 0:h:2;
 midpoint = (x(1:end-1)+x(2:end))./2;
 y = 4*midpoint.^3;   %f(x) = 4*x^3;
 s = sum(h*y)

Trapezoid Rule用梯形去逼近

 trapz();%梯形数值积分
 eg:
 h = 0.05;
 x = 0:h:2;
 y = 4*x.^3;
 s = h*trapz(y);  
 OR:
 h = 0.05;
 x = 0:h:2;
 y = 4*x.^3;
 trapezoid = (y(1:end-1)+y(2:end))/2;
 s = h*sum(trapezoid);

Simpson's Rule

 h = 0.05;
 x = 0:h:2;
 y = 4*x.^3;
 s = h/3*(y(1)+2*sum(y(3:2:end-2))+4*sum(y(2:2:end))+y(end))

Funtion Handles(@)

function [y] = xy_plot(input,x)   %丢入类似@sin ; 一个函数不能作为input
% xy_plot receives the handle of a function and plots that
%function of x
y = input(x);
plot(x,y,'r--');
xlabel('x');
ylabel('function(x)');
end integral();
eg:
y = @(x) 1/(x.^3-2*x-5);
integral(y,0,2) %0,2是上下限

Double and Triple Integrals

eg1:
f = @(x,y) y.*sin(x)+x.*cos(y);
integral2(f,pi,2*pi,0,pi) %二重积分,顺序跟书写的一样 eg2:
f = @(x,y,z) y.*sin(x)+z.*cos(y);
integral3(f,0,pi,0,1,-1,1);

最新文章

  1. git克隆项目到本地&&全局安装依赖项目&&安装依赖包&&启动服务
  2. ACM 独木舟上的旅行
  3. Logcat 不显示日志的另一个原因. 跟cocos2dx关系不大.
  4. HBase读写路径的工作机制
  5. struts2基于Convention插件的约定映射使用
  6. 修正android cocos2dx项目当点击属性时提示错误的问题
  7. ORACLE集合常用方法
  8. 页面刷新vuex数据消失问题解决方案
  9. layui 的学习
  10. AOP切面实现原理以及多个切面切同一个地方时的优先级讲解
  11. How to monitor tempdb in MS SQL
  12. 一个优秀windows C++ 程序员该有哪些知识
  13. Web Services基础学习(W3C)
  14. 关于vc工程包含多个lib库老是提示无法打开问题
  15. 廖雪峰Python学习笔记——序列化
  16. jmeter线程组 讲解
  17. Android 实现瀑布流的两种思路
  18. Django--登录实例
  19. Linux执行shell脚本方式及区别&命令后台运行
  20. mysql用户管理(新增用户及权限管理)

热门文章

  1. react中如何正确使用setState(附例子)
  2. VS不能生成moc_XXX文件的问题解决
  3. mathcurve.com
  4. torch.squeeze函数解释,torch.FloatTensor()函数作用解释
  5. 常见的SPA首屏优化方式
  6. PyMySQL更新
  7. 305-基于XC7Z020的AI 人工智能 可编程相机
  8. js实现字符串得填充
  9. Java基础之类型转换
  10. antDesignVue表格