Efficient Summation in MATLAB for Biphasic Model: Varying n from 0-3 to 0-100

Click For Summary

Discussion Overview

The discussion revolves around implementing a summation in MATLAB for a biphasic model, specifically varying the parameter n from 0 to 3 and then from 0 to 100. Participants are sharing code snippets and troubleshooting errors related to their implementations.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • One participant shares a MATLAB equation for a biphasic model and seeks guidance on how to implement a summation over n.
  • Another participant suggests defining the summation expression as f(n) and provides a code snippet for summing over n from 0 to 3 and then from 0 to 100.
  • A participant reports an error related to subscript indices while attempting to sum the function f(n) and shares their code for further assistance.
  • Another participant points out that directly calling the expression for f(n) may lead to errors, implying that the summation needs to be handled differently.

Areas of Agreement / Disagreement

There is no consensus on the correct implementation of the summation, as participants are experiencing different errors and providing varying approaches to the problem.

Contextual Notes

Participants are encountering issues with subscript indices and the proper definition of the summation function, indicating potential misunderstandings in MATLAB syntax or logic.

tunk
Messages
5
Reaction score
0
i need to write this into MATLAB

http://www.engin.umich.edu/class/bme456/ch10fitbiphasic/biphasfit19.gif

which i have done here:

uj = (-sig/Ha)*(xj-(((2*h)/(pi^2))*((((-1)^n)/((n+1/2)^(1/2)))*sin((n+1/2)*((pi*xj)/h))*exp(((-Ha*ko)/(h^2))*((n+1/2)^2)*(pi^2)*t))));

how do i vary n, and get the equation to sum over n=0-3? and then again from n=0-100?
 
Last edited by a moderator:
Physics news on Phys.org
Call everything inside the summation f(n)

for i=1:4 %n from 0 to 3 case
y(i) = f(i-1)
end

sum(y);

for i=1:101 %n from 0 to 3 case
y(i) = f(i-1)
end

sum(y);

-----

Should work
 
Feldoh said:
Call everything inside the summation f(n)

for i=1:4 %n from 0 to 3 case
y(i) = f(i-1)
end

sum(y);

for i=1:101 %n from 0 to 3 case
y(i) = f(i-1)
end

sum(y);

-----

Should work

I got the following error for the same equation, following your summation of f(n),
"? Subscript indices must either be real positive integers or
logicals.

Error in ==> scriptrun at 16
f(n)=sum(((abs((-1).^n))/((n+1./2).^(2))));"




My code:

for i=1:3 %n from 0 to 2 case
f(n)=sum(((abs((-1).^n))/((n+1./2).^(2))));
y(i)=f(i-1);
end
sum(y);
uj = (-sig/Ha)*(xj-(((2*h)/(pi^2))*f(n)*sin((n+1/2)*((pi*xj)/h))*exp(((-Ha*ko)/(h^2))*((n+1/2)^2)*(pi^2)*t)));

Any advise?
 
You're summing uj = (-sig/Ha)*(xj-(((2*h)/(pi^2))*f(n)*sin((n+1/2)*((pi*xj)/h))*exp(((-Ha*ko)/(h^2))*((n+1/2)^2)*(pi^2)*t))) that's what f(n) is. just calling that expression will give an error, I believe.
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
18K