How to insert function in matlab

11 ビュー (過去 30 日間)
Rachel Barbera
Rachel Barbera 2018 年 1 月 22 日
回答済み: Star Strider 2018 年 1 月 22 日
How can I insert these functions in matlab?
f1= 3 cos (x+2theta) f2= 3 exp(-3x/pi)
x vary from 0 to 2pi

回答 (1 件)

Star Strider
Star Strider 2018 年 1 月 22 日
If you want to evaluate them as statements:
theta = pi/2; % Choose A Value
x = linspace(0, 2*pi, 50);
f1 = 3*cos(x+2*theta)
f2 = 3*exp(-3*x/pi)
If you want to define them as functions themselves, define them as Anonymous Functions (link) as:
f1 = @(x,theta) 3*cos(x+2*theta)
f2 = @(x) 3*exp(-3*x/pi)
then call them as you would any other function.
For ‘f1’, the easiest way to evaluate it with multiple (vector) values for ‘x’ and ‘theta’ is to use the results of the meshgrid (link) function.

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by