Implementing a sum of series with a sum of series
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Rik
el 18 de Sept. de 2021
Why do you think this is incorrect? (note that I did not look in detail at the implementation)
Respuestas (1)
Nipun
el 3 de Jun. de 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
0 comentarios
Ver también
Categorías
Más información sobre Particle & Nuclear Physics en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!