how to define that function in matlab

1 回表示 (過去 30 日間)
Rohan Karmacharya
Rohan Karmacharya 2021 年 7 月 25 日
編集済み: DGM 2021 年 7 月 25 日

回答 (1 件)

DGM
DGM 2021 年 7 月 25 日
編集済み: DGM 2021 年 7 月 25 日
I could bark out the boilerplate response for low-effort copypasted homework questions, but I'm out of breath today. Let's settle for a compromise. Here's a conceptual example that is intentionally not exactly what you need, but can be rearranged with some minor effort.
f = @(x) (x.^2 + 2*x +2) ./ (exp(x) + x.^(1/2) .* cos(x)); % define function
out = f(1:15) % evaluate the function at some integer values
out = 1×15
1.5344 1.4705 0.9254 0.4879 0.2482 0.1232 0.0592 0.0275 0.0125 0.0055 0.0024 0.0010 0.0004 0.0002 0.0001
This example defines an anonymous function, which should be sufficient for the task, but there are other ways to define a function. Refer to the docs:

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by