This looks really simple. I want to define a function:
syms x
f = x^2
I want to be able to do f(4) and it spits out 16. I also want to avoid having to write a new m-file.
When dealing with symbolic variables, to substitute in a numeric value, use subs(), i.e. symbolic substitution:
syms x
f = x^2
subs(f,4)
>> f = @(x) x^2;
>> f(4)
ans =
16
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With