# Mathematical Equations to MATLAB

1 view (last 30 days)

Show older comments

I am trying to implement a method for a reliability problem based on the following article main.pdf (sciencedirectassets.com). I am facing some problems while expressing the mathematical equations to MATLAB.

- All required parameters are given as shown bellow.
- lambda_i is given so that's why I am expressing it bellow right after '%Equations'

Could you help me express the series of sum from (1 to N+1) of MTBFi from denominator, and the series of sum (from i to N) of the integral f(i)*(tau_i)*dtau_i from 0 to Xi?

Also, I don't get when the lambda_i_plus_one is used on the CTM equation, any ideas?

%Parameters

beta = 2;alpha = 200;Ccl = 2000;Cpm = 2500;Rl = 1100;Cren = 50000;delta = 0.223;P = 12;N = 8; Clog = 1600;

%Equations

lambda_i = @(t) (beta / alpha) * (t / alpha).^(beta - 1); %It is given

lambda_i_plus_1 = @(t) exp(delta) * lambda_i(t);

f_i = @(t) lambda_i(t) .* exp(-integral(lambda_i(t), 0, t));

integral_MTBF = @(tau_i) tau_i .* f_i(tau_i); % This doesn't work right

MTBF_i = integral(integral_MTBF, 0, Inf); % This doesn't work right

Xi = MTBF + P; % MTBF should be a vector so that Xi will take values from 1 to N as article says.

%CTM

numerator=Rl*P*(sum_of_integrals)+(N*(Cpm+Ccl+Clog))+((Rl*P)+Ccl+Cren+Clog);

denominator=((N+1)*P)+(series_of_sum);

CTM=num/den

##### 0 Comments

### Accepted Answer

Torsten
on 20 Jun 2024

Edited: Torsten
on 20 Jun 2024

%Parameters

beta = 2;

alpha = 200;

Ccl = 2000;

Cpm = 2500;

Rl = 1100;

Cren = 50000;

delta = 0.223;

P = 12;

N = 8;

Clog = 1600;

%Equations

lambda = @(t) (beta / alpha) * (t / alpha).^(beta - 1);

for i = 1:N+1

f = @(t) lambda(t).*exp(-integral(lambda, 0, t));

MTBF(i) = integral(@(t)t.*f(t),0,Inf,'ArrayValued',1);

integrals(i) = integral(f,0,MTBF(i)+P,'ArrayValued',1);

lambda = @(t)lambda(t)*exp(delta);

end

num=Rl*P*sum(integrals(1:N))+N*(Cpm+Ccl+Clog)+Rl*P+Ccl+Cren+Clog;

den=(N+1)*P+sum(MTBF);

CTM=num/den

##### 0 Comments

### More Answers (1)

Steven Lord
on 20 Jun 2024

This line of your code is the first problem. I've commented it out so I can run other code later in my answer.

% f_i = @(t) lambda_i(t) .* exp(-integral(lambda_i(t), 0, t));

This line evaluates the function handle lambda_i at the values passed into f_i to obtain a numeric array and passes that numeric array into the integral function. That won't work. integral requires a function handle as its first input, so that it can evaluate the function with inputs of its choosing. Try:

% f_i = @(t) lambda_i(t) .* exp(-integral(lambda_i, 0, t));

But with this change, now you have a different problem. On the line where you try to integrate integral_MTBF integral will call integral_MTBF with a vector as input. This means f_i will be called with a vector as input and so the limit of integration in the integral call inside f_i will also be a vector. integral doesn't support this. Instead you're going to need to force the integral call in the line that defines MTBF_i to call integral_MTBF with scalars by telling it your function is array valued. Now it runs to completion through that line.

%Parameters

beta = 2;alpha = 200;Ccl = 2000;Cpm = 2500;Rl = 1100;Cren = 50000;delta = 0.223;P = 12;N = 8; Clog = 1600;

%Equations

lambda_i = @(t) (beta / alpha) * (t / alpha).^(beta - 1); %It is given

lambda_i_plus_1 = @(t) exp(delta) * lambda_i(t);

f_i = @(t) lambda_i(t) .* exp(-integral(lambda_i, 0, t)); % THIS LINE CHANGED

integral_MTBF = @(tau_i) tau_i .* f_i(tau_i); % This doesn't work right

MTBF_i = integral(integral_MTBF, 0, Inf, ArrayValued = true) % THIS LINE CHANGED

After this point I still receive errors when I run your code, but they're related to some of the variables (MTBF and sum_of_integrals were the first two MATLAB complained about) not being defined so you're going to need to correct those errors.

Xi = MTBF + P; % MTBF should be a vector so that Xi will take values from 1 to N as article says.

%CTM

numerator=Rl*P*(sum_of_integrals)+(N*(Cpm+Ccl+Clog))+((Rl*P)+Ccl+Cren+Clog);

denominator=((N+1)*P)+(series_of_sum);

CTM=num/den

##### 3 Comments

Steven Lord
on 20 Jun 2024

### See Also

### Community Treasure Hunt

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

Start Hunting!