Clear Filters
Clear Filters

Implementing a sum of series with a sum of series

1 view (last 30 days)
I am having trouble implementing a formula shown below:
Specifically, the sum of series with a sum of series. I am currently using nested for loops to execute this but I don't think my execution is correct.
a,b,C are constants
D(t0) = 0 in this case so it is omitted
trajectoryArraywithShear is a cell array with matrices sized (nx5) with the tau (shear) values
dose1 in this case is the to calculate the first sum of series
totDose1 is the cumulative dose (BDI(t))
a1 = 0.77;
b1 = 3.075;
C1 = 3.31 * 10^-6;
BDI1 = 0;
for z = 1:length(trajectoryArraywithShear) %for each trajectory, where tau is located
totDose1 = 0; %set initial total dose to 0;
for w = 1:size(trajectoryArraywithShear{z},1) %for the size of the trajectory
dose1 = 0;
for r = 1:w %dose1 at r = 1 is 0
dose1 = dose1 + trajectoryArraywithShear{z}(r,5)^(b1/a1) * timeStep;
end
dose1 = dose1^(a1-1);
totDose1 = totDose1 + (C1 * a1 * dose1 * timeStep * trajectoryArraywithShear{z}(w,5)^(b1/a1));
end
BDI1 = totDose1;
trajectoryArraywithShear{z}(1,6) = BDI1;
  1 Comment
Rik
Rik on 18 Sep 2021
Why do you think this is incorrect? (note that I did not look in detail at the implementation)

Sign in to comment.

Answers (1)

Nipun
Nipun on 3 Jun 2024
Hi Curtis,
I understand that you want to implement the given formula in MATLAB without using nested loops. Here is how you can do it using matrix operations:
a1 = 0.77;
b1 = 3.075;
C1 = 3.31 * 10^-6;
timeStep = ...; % Define your time step
trajectoryArraywithShear = ...; % Your input cell array
BDI1 = 0;
for z = 1:length(trajectoryArraywithShear)
tau = trajectoryArraywithShear{z}(:, 5);
n = length(tau);
T = tril(repmat(tau.^(b1/a1) * timeStep, 1, n));
dose1 = sum(T, 2).^(a1 - 1);
totDose1 = C1 * a1 * sum(dose1 .* tau.^(b1/a1) * timeStep);
BDI1 = totDose1;
trajectoryArraywithShear{z}(1, 6) = BDI1;
end
Refer to the following MathWorks documentation for matrix indexing and operations in MATLAB: https://www.mathworks.com/company/technical-articles/matrix-indexing-in-matlab.html
Hope this helps.
Regards,
Nipun

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!