如何修复此Matlab代码? [英] How Do I Fix This Matlab Code?

查看:198
本文介绍了如何修复此Matlab代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MATLAB帮助!!!泰勒系列?

i必须编写一个matlab函数,接受以下输入并产生以下

输入:

1)f函数,以字符串形式输入'f'

2)泰勒系列的中心

3)泰勒多项式的n度

输出:

1)P n-th泰勒多项式偏离中心a





i需要输出P度数的函数多项式集中在一个

这里是我的代码,它的工作几乎完美,但我不知道如何在a中获得函数的衍生物而不会损害我的(xa)术语...

从我看到的差异(f,k)计算f的k阶导数,​​但是不能在a中插入

。看起来我的代码将需要另一个matlab函数来插入任何建议吗?



函数[P] = mytaylor(f,a,n)

f = sym(f);

syms x;

terms = 0;

for k = 0:n

fk = diff(f,k);

terms = terms + fk *(xa)^(k)/ factorial(k);

结束

P =条款;

MATLAB HELP !!! TAYLOR SERIES?
i have to write a matlab function that accepts the following inputs and yields the following
inputs:
1)f function, inputted as a string 'f'
2)a center of the taylor series
3)n degree of the taylor polynomial
output:
1) P n-th degree taylor polynomial off centered at a


i need the function to output a P nth degree taylor polynomial centered at a
here is the code i have , it works almost perfect but im not sure how to get the derivatives of the functions at "a" with out compromising my (x-a) term...
from what i see the diff(f,k) computes the kth derivative of f, but can not plug
in the a. looks my code will require another matlab function that will do the plugging any suggestions?

function [P] = mytaylor(f,a,n)
f=sym(f);
syms x ;
terms=0;
for k=0:n
fk=diff(f,k);
terms = terms + fk*(x-a)^(k)/factorial(k);
end
P=terms;

推荐答案

这篇关于如何修复此Matlab代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆