How can I get values for f in a matrix of dimension(100,1)?

1 回表示 (過去 30 日間)
athi
athi 2017 年 9 月 18 日
回答済み: Jan 2017 年 9 月 18 日
for x=linspace(-1,1,10)
for y=linspace(-1,1,10)
f= (1-x).^2 +100*(y-x.^2).^2
end
end

回答 (2 件)

José-Luis
José-Luis 2017 年 9 月 18 日
編集済み: José-Luis 2017 年 9 月 18 日
f =@(x,y) (1-x).^2 +100*(y-x.^2).^2;
dummy = linspace(-1,1,10);
[xx,yy] = ndgrid(dummy,dummy);
result = f(xx,yy);
result = result(:);
Alternatively:
result = bsxfun(f,dummy,dummy.');
result = result(:);

Jan
Jan 2017 年 9 月 18 日
Since R2016b with auto-expanding:
x = linspace(-1,1,10);
y = linspace(-1,1,10).';
f = (1-x).^2 + 100*(y - x.^2).^2;
f = f(:)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by