Finding Zero of Sum of Functions by Iteration

11 vues (au cours des 30 derniers jours)
Gregory McArthur
Gregory McArthur le 22 Déc 2015
I am trying to sum a function and then attempting to find the root of said function. That is, for example, take:
Consider that I have a matrix, X, and vector, t, of values: X(2*n+1,n+1), t(n+1)
for j = 1:n+1
sum = 0;
for i = 1:2*j+1
f = @(g)exp[-exp[X(i,j)+g]*(t(j+1)-t(j))];
sum = sum + f;
end
fzero(sum,0)
end
That is,
I want to evaluate at
j = 1
f = @(g)exp[-exp[X(1,1)+g]*(t(j+1)-t(j))]
fzero(f,0)
j = 2
f = @(g)exp[-exp[X(1,2)+g]*(t(j+1)-t(j))] + exp[-exp[X(2,2)+g]*(t(j+1)-t(j))] + exp[-exp[X(3,2)+g]*(t(j+1)-t(j))]
fzero(f,0)
j = 3
etc...
However, I have no idea how to actually implement this in practice.
Any help is appreciated!
PS - I do not have the symbolic toolbox in Matlab.

Réponse acceptée

jgg
jgg le 22 Déc 2015
Modifié(e) : jgg le 22 Déc 2015
I think the solution is to write a function:
function [ sum ] = func(j,g,t,X)
sum = 0;
for i = 1:2*j+1
f = exp(-exp(X(i,j)+g)*(t(j+1)-t(j)));
sum = sum + f;
end
end
Then loop your solver
for j=1:n
fun = @(g)func(j,g,t,X);
fzero(fun,0)
end
You'll have to debug the function inside( f = stuff ) (since I don't know what it's supposed to do) so that it returns what you want, but this should solve your problem.
I can get this to solve, but I'm not sure if your f function does what you want it to do.
  1 commentaire
Gregory McArthur
Gregory McArthur le 22 Déc 2015
Modifié(e) : Gregory McArthur le 22 Déc 2015
This is really impressive, actually, and probably what I would do if I was better at MATLAB.
Thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics 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!

Translated by