Finding a summation of a two variable function keeping one parameter constant.
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Sushanth Manchikatla
il 18 Mar 2021
Risposto: Michael Soskind
il 18 Mar 2021
I need to do a summation of a function f(x,n) such that x remains as a variable in the process and n varies from 1 to N ( like 1:100 or something).
So I need f(x,1) + f(x,2) + f(x,3) ........... + f(x,N) in a variable SUM, such that SUM could work like a function handle, with x alone as its argument.
f(x,n) is any arbitrary function.
How do I do this in MATLAB?
0 Commenti
Risposta accettata
Michael Soskind
il 18 Mar 2021
Sushanth,
The method for doing this depends on your function f(x,N).
If this function works with vectors, then the easiest function for this would be something in the form:
N = 1:100;
sum_function = @(x) sum(f(x, N)); % Assuming f(x,N) can take a vector N and is already defined
Then, calling sum_function(10) would provide the summation with x = 10.
Alternatively, you could make a function that only accepts X, and a range to sum over, and go through a for loop summing the values over that range. However, that is up to you.
Hope that helps,
Michael
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!