Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
Steven
Steven le 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 commentaire
Steven
Steven le 19 Sep 2013
If this helps x = linspace(-1,2,100).

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 19 Sep 2013
And to be complete:
y = x.^2;
y(x < 1) = x(x < 1);

Plus de réponses (2)

James Tursa
James Tursa le 19 Sep 2013
y = x;
y(y<1) = 1;
y = y.*x;

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

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by