Sum functions code in matlab
22 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I wrote this matlab codes but I fear something might be wrong.
function F = myfun (x)
format long
syms beta alpha lambda omega n I
n=100;
F1=n-symsum(beta*x(i)^alpha*exp(lambda*x(i)),1,n)-2*symsum(beta*omega*x(i)^alpha*exp(-beta*x(i)^alpha*exp(lambda*x(i))+lambda*x(i))*(1-omega*exp(-beta*x(i)^alpha*exp(lambda*x(i))))^(-1),1,n);
F2=symsum(log(x(i)),1,n)+symsum(1/(alpha+lambda*x(i)),1,n)-symsum(beta*x(i)^alpha*exp(lambda*x(i))*log(x(i)),1,n)-2*symsum(alpha*omega*x(i)^alpha*exp(-beta*x(i)^alpha*exp(lambda*x(i))+lambda*x(i))*log(x(i))*
(1-omega*exp(-beta*x(i)^alpha*exp(lambda*x(i))))^(-1),1,n);
F3=symsum(x(i)/(alpha+lambda*x(i)),1,n)-symsum(beta*x(i)^(alpha+1)*exp(lambda*x(i)),1,n)-symsum(x(i),i,n)--2*symsum(beta*omega*x(i)^(alpha+1)*exp(-beta*x(i)^alpha*exp(lambda*x(i))+lambda*x(i))*(1-omega*exp(-beta*x(i)^alpha*exp(lambda*x(i))))^(-1),1,n);
F4=n/(1-omega)-2*syms(exp(beta*x(i)^alpha*exp(lambda*x(i)))*(1-omega*exp(-beta*x(i)^alpha*exp(lambda*x(i))))^(-1),1,n);
I wish to know if I am correct with the this matlab codes and the look of each function mathematically.
Thank you
0 Commenti
Risposte (1)
Walter Roberson
il 30 Mar 2016
No, that code cannot be correct, as it tries to index with the variable "i" that you have not defined. The default value for the variable named "i" happens to be sqrt(-1) which is something you cannot index by.
You should be using
syms i
and listing i in your symsum(), in the form
symsum(EXPRESSION, i, 1, n)
However! A recent posting explored that you cannot index by a symbolic variable. So you should not be using symsum(). You should be using regular sum()
For example,
symsum(beta*x(i)^alpha*exp(lambda*x(i)),1,n)
but
sum(beta .* x.^alpha .* exp(lambda .* x))
0 Commenti
Vedere anche
Categorie
Scopri di più su Calculus 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!