functions with different conditions

4 次查看(过去 30 天)
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.

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by