필터 지우기
필터 지우기

How to convert into function handle?

조회 수: 2 (최근 30일)
Max
Max 2016년 2월 10일
댓글: Adam 2016년 2월 10일
Hello guys,
I have a little problem with the convertion into function handle. I wrote the source-code below and would like to do the same but not in symbolic variables. I would like to use function handles. But the code doesn´t work.
Can anybody help me, please?
tfail = [3850,4340,4760,3300,3720,4080,2750,3100,3400];
n=length(tfail);
beta_hat =13.502152;
B_hat = 1861.328876;
C_hat=39.624407;
syms t B beta C
y(t) = (exp(-B/((heaviside(t)-heaviside(t-2000))*(330)+(heaviside(t-2000)-heaviside(t-3000))*(350)+...
(heaviside(t-3000)-heaviside(t-5000))*(390))))/C;
logL=0;
for i=1:n
tfail(i);
%%function handle
ynum=matlabFunction(y);
Inum=@(x)integral(ynum,0,tfail(i));
Rnum=@(x)exp(-(Fnum(x)).^beta);
%%Symbolic
I(i) = int(y(t),t,0,tfail(i));
y_new(i)=subs(y,t,tfail(i));
logL =logL+log((beta*y_new(i)*(I(i))^(beta-1))*exp(-((I(i))^beta)));
end
%%Symbolic
p = int(y(t),t,0,4000);
u = beta*log(p);
u_hat=subs(u,{beta,B,C},{beta_hat,B_hat,C_hat})
  댓글 수: 2
Jan
Jan 2016년 2월 10일
And what should be converted to a functionhandle? What does "it does not work" mean explicitly? Do you get an error message or do the results differ from your expectations?
Adam
Adam 2016년 2월 10일
You should also post the attempt without using symbolic variables since it sounds like you have at least made an attempt at this to find that it doesn't work.
I'm probably not the only one who knows nothing about the Symbolic toolbox, but know enough about function handles to spot problems in code using them.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by