Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use matlab anonymous function

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "how to use matlab anonymous function". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to use matlab anonymous function" can help you solve the problem.

Anonymous function

In later versions of Matlab7.0

There is a new type of function-anonymous function.

Not only can it complete the original version

The function of inline function (inline)

It also provides other more convenient features.

1, the basic usage of anonymous functions

Handle = @ (arglist) anonymous_function

Where handle is the name used when calling anonymous functions

Arglist is the input parameter of the anonymous function

It can be one or more, separated by commas

Anonymous_function is an expression of an anonymous function

An example is as follows:

> > fallow @ (xPowery) x ^ 2 + y ^ 2

> > f (1pc2)

Ans =

five

Of course, it is possible to enter an array:

> fallow @ (xPowery) x.^ 2 + y.^ 2;% pay attention to the point (.) Operation

> > axi1VO1VOLING 10

> > baked 10, color 1, color 1,

> > f (afort b)

Ans =

one hundred and one

eighty-five

seventy-three

sixty-five

sixty-one

sixty-one

sixty-five

seventy-three

eighty-five

one hundred and one

Parameters can also be passed in the expression of an anonymous function, such as:

> > axi1purl 5

> > bang 5lu lu 1

> > cymbals 0.1purl 0.1purs0.5

> fallow @ (xpene y) x.^ 2 + y.^ 2 + c

> > f (afort b)

Ans =

26.1000

20.2000

18.3000

20.4000

26.5000

C is used as a parameter in the expression to pass the data.

The above are all single anonymous functions.

You can also construct multiple anonymous functions, such as:

> fallow @ (xPowery) @ (a) x ^ 2 + y ^ + a

> > f1fuf (2pcm3)

F1 =

@ (a) x ^ 2 + y ^ + a

> > f2=f1 (4)

F2 =

eighty-five

Each parameter after @ starts to work from behind it.

Until the end of the expression.

two。 Using anonymous function to realize the assignment operation of symbolic function

In the old version of Matlab

This function is done by the inline function

Now use anonymous functions to do this.

For example: know z = 2x ^ 3 + 4x+5

Find the second derivative of z at xtriple 3

The expression of the second derivative of z can be calculated by using the symbolic function.

Then assign x to the value of 3 through an anonymous function

Get the final result:

> > syms x;% defines symbolic variables

> > zonal 2* x ^ 3 + 4*x+5

% define expression

> > z1=diff (zpj2)

The expression Z1 = 12x for finding the second derivative of z

> > z2=eval_r (['@ (x) 'vectorize (Z1)])

The function of the% vectorize function is

The rule to make inline functions suitable for array operations

> > Z2 (3)

Ans =

thirty-six

This is the end of the content about "how to use matlab anonymous functions". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report