How do I multiply a given function handle with the independent variable?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Saurabh Madankar
le 3 Avr 2023
Réponse apportée : Steven Lord
le 3 Avr 2023
I have pre-defined n number of function handles f_{i} which are functions of t for i = 1 to n. How do I define a new function g_{i} = t.f_{i} and then evaluate the integral of each g_{i} from t=0 to 1?
0 commentaires
Réponse acceptée
Steven Lord
le 3 Avr 2023
f = @sin;
g = @(t) t.*f(t);
format longg
[3*sin(3); g(3)] % Spot check by evaluating the function at t = 3
Now you can use g like any other function handle in functions like integral.
numericAnswer = integral(g, 0, 2*pi)
syms x
symbolicAnswer = int(x.*sin(x), 0, 2*pi) % or
symbolicAnswer = int(g(x), 0, 2*pi)
[numericAnswer; double(symbolicAnswer)]
0 commentaires
Plus de réponses (1)
埃博拉酱
le 3 Avr 2023
Use symfun and int in Symbolic Math Toolbox if you want to do integrals.
0 commentaires
Voir également
Catégories
En savoir plus sur Formula Manipulation and Simplification 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!