MatLab学习作业之多项式与数值微积分(台大郭彦甫)

Practice
一:Plot the polynomial ?(?) = (5?3 − 7?2 + 5? + 10)(4?2 + 12? − 3) and its derivative for −2 ≤ ? ≤ 1
%第一个练习不是很难
%用conv实现两多项式的乘法
%在运用handle将图片加粗,唯一不明白在于图像legend中英文 ’ 的输入不太懂,因为会与本身语法 ‘ ’冲突
u=[5 -7 5 10];
v=[4 12 -3];
h=conv(u,v);
x=-2:0.01:1
f=polyval(h,x);
f1=polyval(polyder(h),x);
p=plot(x,f,‘b–’,x,f1,‘r-’);
set(p,‘LineWidth’,2)
xlabel(‘x’)
legend(‘f(x)’,‘f’(x)’)
二:Given ?(?) = sin(?), write a script to find the error of ?′(?0) at ?0 = ?/2 using various ℎ
%运用for循环实现
%导数的求通过定义求得运用 diff函数(后减前)
clc
clear all
x0 = pi/2;
i=1;
h=0.1;
error=ones(1,7);
for i=1:1:7
x = [x0 x0+h];
y = [sin(x0) sin(x0+h)];
error(i)= diff(y)./diff(x)-0
h=h.0.1
end
三:Given ?(?) = ?−? sin(?2/2), plot the approximate derivatives ?′ of ℎ = 0.1, 0.01, and 0.001
%运用彩色标定,新函数colormap
%循环从定义入手得到导数画图
g = colormap(lines); hold on;
for i=1:3
x = 0:power(10, -i):2
pi;
y = exp(-x).*sin((x.x)/2); m = diff(y)./diff(x);
plot(x(1:end-1), m, ‘Color’, g(i,:));
end
hold off;
set(gca, ‘XTick’, 0:pi/2:2
pi);
set(gca, ‘XTickLabel’, {‘0’, ‘π/2’, ‘π’,‘3π/2’,‘2π’});
h = legend(‘h=0.1’,‘h=0.01’,‘h=0.001’);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值