functions with different conditions

8 vues (au cours des 30 derniers jours)
Ruben Hedström
Ruben Hedström le 14 Déc 2018
If I have the conditions f(x) = {x^2, x>1 and x^4, x<=1}
How would I write this as a function with format f = @(x) ...... Can I do something like f=@(x) (x^2,x>1; x^4, x<=1);?
I also want to intergrate this afterwards like integral(f,0,2); for example.

Réponse acceptée

Stephen23
Stephen23 le 14 Déc 2018
>> f = @(x) x.^2.*(x>1) + x.^4.*(x<=1);
>> integral(f,0,2)
ans = 2.5333

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by