MATLAB Answers

Steven

Create An Array That Contains All the Values of F(x)? Help!

Asked by Steven
on 19 Sep 2013

I have a function f(x) that equals x if x < 1 and x^2 elsewhere.

How would I go about putting all the values of f(x) into another array, named y, for example?

  1 Comment

Steven
on 19 Sep 2013

If this helps x = linspace(-1,2,100).

Products

No products are associated with this question.

3 Answers

Answer by Jan Simon
on 19 Sep 2013
 Accepted answer

And to be complete:

y = x.^2;
y(x < 1) = x(x < 1);

  0 Comments


Answer by James Tursa
on 19 Sep 2013

y = x;

y(y<1) = 1;

y = y.*x;

  0 Comments


Answer by Azzi Abdelmalek
on 19 Sep 2013
x=-5:5
y=(x<1).*x+(x>=1).*x.^2

  0 Comments


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply today