Info
此问题已关闭。 请重新打开它进行编辑或回答。
How can I calculate an integral in a for-loop?
1 次查看(过去 30 天)
显示 更早的评论
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])
1 个评论
回答(0 个)
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!