Implementing a sum of series with a sum of series

1 次查看(过去 30 天)
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 个评论
Rik
Rik 2021-9-18
Why do you think this is incorrect? (note that I did not look in detail at the implementation)

请先登录,再进行评论。

回答(1 个)

Nipun
Nipun 2024-6-3
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

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by