Sum functions code in matlab

조회 수: 22 (최근 30일)
Somario
Somario 2016년 3월 30일
답변: Walter Roberson 2016년 3월 30일
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

답변 (1개)

Walter Roberson
Walter Roberson 2016년 3월 30일
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))

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by