How do I do this function?

1 回表示 (過去 30 日間)
Jonathan Larsson
Jonathan Larsson 2019 年 9 月 29 日
回答済み: John D'Errico 2019 年 9 月 29 日
x=[-1:0.1:1]
f=x.^2.*sin(pi.*x)
How do I solve this function for g in code?
g=f if f>=0
g=0 if f<0
I tried doing:
if f>=0
g=f
else
g=0
end
It didn't save as a matrix, only as g=0
Please help?

回答 (1 件)

John D'Errico
John D'Errico 2019 年 9 月 29 日
x = -1:0.1:1;
f = x.^2.*sin(pi.*x);
g = max(0,f);

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by