search
HomeComputer TutorialsComputer KnowledgeUse MATLAB to calculate the Taylor series expansion coefficients of polynomials

Use MATLAB to calculate the Taylor series expansion coefficients of polynomials

matlab calculates the coefficients of the Taylor series expansion of polynomials

clear;clc;

syms x a;

m=5;%Change it yourself

y=(11/6-3*x 3/2*x^2-1/3*x^3)^a

f=taylor(y,m 1,x);

w=sym(zeros(m 1,1));

w(1)=subs(f,x,0);

f=f-w(1);

for n=m:-1:2

w(n 1)=subs(f-subs(f,x^n,0),x^n,1);

f=f-w(n 1)*x^n;

end

w(2)=subs(f,x,1)

Note that because the matlab array subscript starts from 1, here w(1) is a constant term and w(2) is a linear term, so By analogy,

y=w(1) w(2)*x w(3)*x^2 .... w(m 1)*x^m

How to solve the problem of undetermined coefficients in matlab

【1】Transform the function

>>f=sym('2*x^3 3*x^2 21*x 4-(3*a*x^3 b*x^2 c*x d)=0')

f =

2*x^3 3*x^2 21*x 4-(3*a*x^3 b*x^2 c*x d)=0

【2】Use collect to merge similar items

>>ff=collect(f):

(2-3*a)*x^3 (3-b)*x^2 (21-c)*x 4-d = 0

[3] Use maple to extract polynomial coefficients. If there are many, you can use loop statements.

>>c3=maple('coeff',ff,x,3)

c3 =2-3*a

>>c1=maple('coeff',ff,x,1)

c1 =21-c

>>c2=maple('coeff',ff,x,2)

c2 =3-b

>>c0=maple('coeff',ff,x,0)

c0 =4-d

Replenish:

This time it turned out like this, the program worked, but I’m not very satisfied. How about we sort it out together?

syms a b c d x

%【1】Transform the function

f=sym('2*x^3 3*x^2 21*x 4-(3*a*x^3 b*x^2 c*x d)')

N=3;

for i=0:N

temp=maple('coeff',f,x,N-i);

cp(1,i 1)={temp};

end

celldisp(cp);

Additional addition: This time it is finally solved, but it looks very stupid and not very ideal. I just make do with it. Of course, I believe it can be modified to be beautiful.

syms a b c d x

f=sym('2*x^3 3*x^2 21*x 4-(3*a*x^3 b*x^2 c*x d)')

N=3;

for i=0:N

temp=maple('coeff',f,x,N-i);

temp1(i 1)=temp;

end

cp=temp1

a=solve(cp(1)), b=solve(cp(2)), c=solve(cp(3)), d=solve(cp(4))

operation result:

a =2/3

b =3

c =21

d =4

The functional formula M file for the value of polynomial Px anxn an1xn1 a1x a0 is used

First of all, the polynomial is dynamic, so this must be an input term of matlab;

Secondly, the Matlab expression of polynomials must be clear. It is to extract the coefficients of the polynomials after lowering the power to represent the polynomial. The -n degree polynomial of the polynomial is represented by an n 1-dimensional vector; for example, the polynomial 3*x^2 5 in matlab Expressed as [3 0 5];

Finally, you need to understand the matlab method of polynomial function value, which is the command polyval.

Based on the above, the M file is as follows:

function val = fpolyval(p,x)

% Function fpolyval Function: Function value val of polynomial p at x.

% The input item p is the coefficient of the polynomial arranged in descending powers;

val = polyval(p,x);

For example: 3*x^2 5 value at x=1,2

>>p=[3 0 5];

>>x=[1 2];

>>val=fpolyval(p,x)

val =

8 17

The above is the detailed content of Use MATLAB to calculate the Taylor series expansion coefficients of polynomials. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:Excel办公网. If there is any infringement, please contact admin@php.cn delete
Fixes for ExpressVPN Not Connecting on Windows PC/Mac/iPhone - MiniToolFixes for ExpressVPN Not Connecting on Windows PC/Mac/iPhone - MiniToolMay 01, 2025 am 12:51 AM

Is ExpressVPN not connecting on iPhone, Android phone, Mac, or Windows PC? What should you do if ExpressVPN won’t connect or work? Take it easy and go to find solutions from this post. Here, php.cn collects multiple ways to solve this internet issue.

Targeted Solutions for 100% GPU Usage on Windows 10/11Targeted Solutions for 100% GPU Usage on Windows 10/11May 01, 2025 am 12:50 AM

Is 100% GPU usage bad? How to fix 100% GPU usage in Windows 10? Don’t fret. php.cn Website provides you with this article to work out high GPU issues. Those methods are worth a try if you are undergoing 100% GPU usage.

How to Download/Install/Add/Remove/Disable Add-ins in Word - MiniToolHow to Download/Install/Add/Remove/Disable Add-ins in Word - MiniToolMay 01, 2025 am 12:49 AM

You can use add-ins in Microsoft Word to get more features. This post introduces how to download, install, add or remove add-ins in Microsoft Word. A free file recovery method is also provided to help you recover deleted/lost Word or any other files.

Fix the System Backup Error Codes 0x807800A1 & 0X800423F3 - MiniToolFix the System Backup Error Codes 0x807800A1 & 0X800423F3 - MiniToolMay 01, 2025 am 12:48 AM

Some people find the system backup error codes 0x807800A1 & 0X800423F3 when they attempt to create a system backup. These codes will prevent you from doing any backup tasks. Don’t worry! This article on php.cn Website will teach you how to fix th

Windows 10 Enterprise ISO Download/Install, Easy Guide to LearnWindows 10 Enterprise ISO Download/Install, Easy Guide to LearnMay 01, 2025 am 12:47 AM

Want to get an ISO file of Windows 10 Enterprise to install it for business usage? Windows 10 Enterprise ISO download & install are easy and php.cn will show you how to download Windows 10 Enterprise ISO 20H2, 21H1, or 21H2 via some direct downlo

NordVPN Not Working on Windows 11: Here Are Easy Fixes - MiniToolNordVPN Not Working on Windows 11: Here Are Easy Fixes - MiniToolMay 01, 2025 am 12:46 AM

NordVPN not connecting or working on your Windows 11 computer? Do you know the reasons for this issue? If you want to solve this problem, do you know what you should do? If you have no idea, you come to the right place. In this post, php.cn Software

Is Twitter Down? How to Check It? How to Fix It? Read This Post! - MiniToolIs Twitter Down? How to Check It? How to Fix It? Read This Post! - MiniToolMay 01, 2025 am 12:45 AM

Nowadays, Twitter becomes more and more popular all over the world. However, sometimes you may find it is not working properly. Is Twitter down? How to check it? How to fix it? This post from php.cn provides details for you.

Redfall Release Date, Trailers, Pre-Order, and Latest News - MiniToolRedfall Release Date, Trailers, Pre-Order, and Latest News - MiniToolMay 01, 2025 am 12:44 AM

When does Redfall come to market? Redfall fans can’t wait to try this game. fortunately, the release date has been clarified and more information we know about Redfall will be all disclosed in this article on php.cn Website, so if you are interested,

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),