Implementing a sum of series with a sum of series
    조회 수: 4 (최근 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
      
      
 2021년 9월 18일
				Why do you think this is incorrect? (note that I did not look in detail at the implementation)
답변 (1개)
  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
댓글 수: 0
참고 항목
카테고리
				Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


