MATLAB Answers

athi
0

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

Asked by athi
on 18 Sep 2017
Latest activity Answered by Jan
on 18 Sep 2017
for x=linspace(-1,1,10)
for y=linspace(-1,1,10)
f= (1-x).^2 +100*(y-x.^2).^2
end
end

  0 Comments

Sign in to comment.

2 Answers

Answer by José-Luis
on 18 Sep 2017
Edited by José-Luis
on 18 Sep 2017

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(:);

  0 Comments

Sign in to comment.


Answer by Jan
on 18 Sep 2017

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(:)

  0 Comments

Sign in to comment.