matlab sin函数怎么写,matlab实现插值法sin函数

本文详细介绍了如何在Matlab中使用插值法实现sin函数,通过示例代码展示函数`sin2(x)`的实现过程,包括计算插值多项式、转换输入值以及绘制图形。此外,还提到了Matlab的画图函数和学习笔记,涉及figure、bsxfun等知识点。
摘要由CSDN通过智能技术生成

插值法实现sin函数:

%calculate and print the sine function

%input: x

%output: sin(x) similar

function y = sin2(x)

%save a copy of x

x_temp = x;

%calculate the interpolation polynomial

%save the coefficient

n = 4;

b = pi/4 + (pi/4)*cos((1:2:2*n-1)*pi/(2*n));

yb = sin(b);

c = newtdd(b, yb, n);c

%for any x, exchange it to base

%interpolation method calculation

len = size(x, 2);

s = ones(1, len);

y = zeros(1, len);

for i = 1 : len

if x(i) < 0

s(i) = s(i) * -1;

x(i) = x(i) * -1;

end

x1(i) = mod(x(i), 2*pi);

if x1(i) > pi

x1(i) = 2*pi-x1(i);

s(i) = s(i) * -1;

end

if x1(i) > pi/2

x1(i) = pi - x1(i);

end

y(i) &

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值