How to convert into function handle?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Jan
il 10 Feb 2016
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
il 10 Feb 2016
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.
Risposte (0)
Vedere anche
Categorie
Scopri di più su Symbolic Math Toolbox 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!