change variable in function_handle

1 view (last 30 days)
hello all,
i wanna to change x in f=@(x)sinx to x+2 so that we have g=(x)sin(x+2)
how can i derive g from f in matlab?
thanks alot

Accepted Answer

the cyclist
the cyclist on 19 May 2021
I think this is what you mean?
% Define f
f=@(x) sin(x);
% Derive g from f
g = @(x) f(x+2);
% Show that it gives expected result
f(2)
ans = 0.9093
g(0)
ans = 0.9093

More Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 19 May 2021
f=@(x)sin(x)
g = @(x)f(x+2)
Good luck

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!