Info

# How can I calculate an integral in a for-loop?

1 view (last 30 days)
Max on 22 Jan 2016
Closed: Walter Roberson on 23 Jan 2016
Hello,
I´ve got a few problems with the code below. What I would like to do ,here, is to evaluate the function logL. Therefore, I have to evaluate the functions (I, y and logL) in the for loop, for all of the four data points, tfail.
But it doesn´t work. I can´t find the mistake. Can somebody help me, please?
clear all; close all
tfail = [5571.760,5573.742,5654.457,6079.693]
n = length(tfail)
beta_hat = 4.2915822
B_hat = 1861.6186657
C_hat = 58.9848692
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-14000))*(390))))/C;
logL=0;
for i=1:n
tfail(i)
I = int(y,t,[0,tfail(i)]) % integrate y from t=0 to t=t(i)
y_new(i)=subs(y,t,tfail(i)) % evaluate y(t) at t=t(i)
logL =logL+log((beta*y_new(i).*(I_(i)).^(beta-1)).*exp(-((I_(i)).^beta)));
end
%%figure(1)
logl = subs(logL,{beta,B,C},{beta_hat,B_hat,C_hat}) % plot logL for different beta, B, C ???
ezplot(logL,[0,4000])