Differentiating a symbolic function by a lot of variables without loop.
Show older comments
Hello. I am trying to create a script to calculate a function error (sqrt(sum(df/dvar * delta var)^2)) [Physics lab course] so I need to differentiate by a different variable each time. If I do this with a for loop, it works. If i try to do this:
exp = sum((diff(f, mat(:, 1))*mat(:, 2)).^2) % Symbolic Expression
it gives this error:
The second argument must be a variable or a nonnegative integer specifying the number of differentiations.
If fore example I change it for diff(f, mat(1, 1)) it gives no error (but differentiates by the same variable of course..)
So, any Ideas how could I do this w/o a loop? thank you! (The loop is:)
for k=1:size(mat, 1);
exp = exp+(diff(f, mat(k, 1))*mat(k, 2))^2;
end
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements 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!