i cant seem to write this function in matlab

5 ビュー (過去 30 日間)
Ahmad al-falahi
Ahmad al-falahi 2018 年 4 月 11 日
回答済み: Steven Lord 2018 年 4 月 11 日
https://uk.mathworks.com/matlabcentral/answers/uploaded_files/112623/dddddddddddddddddddddddddddddd.PNG im trying to write this function in matlab but i cant get it right. this is what im writing in matlab f=@(x)exp(-(x-6).^2)-(x.^2).*cos(x)/(x.^2)+1 what im i doing wrong
  2 件のコメント
Adam
Adam 2018 年 4 月 11 日
You need the last parenthesis outside of the +1
Ahmad al-falahi
Ahmad al-falahi 2018 年 4 月 11 日
well i got a function handle, but when i plot it it looks nothing like it should, when i plot the function on an online site it does ot look like the plot i get in matlab

サインインしてコメントする。

回答 (2 件)

Ahmad al-falahi
Ahmad al-falahi 2018 年 4 月 11 日
this is the function

Steven Lord
Steven Lord 2018 年 4 月 11 日
f=@(x)exp(-(x-6).^2)-(x.^2).*cos(x)/(x.^2)+1
Let's look at a piece of your anonymous function in isolation along with a variant of that piece.
f1 = @(x) cos(x)/(x.^2)+1
f2 = @(x) cos(x)/(x.^2+1)
[f1(2) f2(2)]
f1(2) and f2(2) are different values, so f1 and f2 are different functions. You probably want to use f2 for that piece of f, not f1. You probably also want to use ./ instead of / as that would allow you to specify an array for x, not just a scalar.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by