How to create a loop on function handle
Show older comments
I want to write the following in an efficent way using a loop over j = 1:n. A is n by n matrix, t(i) is a scalar (where i is another index, c is n by 1 vector, and f is a function handle. I want the output to be function handle XI which is an n by 1 vector and whose argument is the vector xi of length n by 1
Here n = 3, but I want it for general n.
A = ones(3,3);
c = ones(3,1);
f = @(t,y) t * y;
XI = @(xi) [xi - (y(i,:) + dt* A(:,1) .* f(t(i)+c(1)*dt,xi(1)) +...
dt* A(:,2) .* f(t(i)+c(2)*dt,xi(2)) +...
dt* A(:,3) .* f(t(i)+c(3)*dt,xi(3)))];
Accepted Answer
More Answers (0)
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!