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

In summary: Also, you don't need to use a summation for this, f(n) is just a function that takes in values of n and outputs the value for uj. So you can just do 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))) for each value of n that you want to plug in.
  • #1
tunk
6
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
  • #2
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
 
  • #3
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?
 
  • #4
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.
 
  • #5


To vary n from 0-3, you can use a for loop in MATLAB. First, define a variable n that ranges from 0 to 3. Then, within the for loop, you can calculate the summation equation for each value of n and add it to a variable (e.g. sum) that stores the total sum. The code would look something like this:

sum = 0; % initialize the sum variable
n = 0:3; % define the range of n
for i = n % loop through each value of n
% calculate the summation equation for the current value of n
uj = (-sig/Ha)*(xj-(((2*h)/(pi^2))*((((-1)^i)/((i+1/2)^(1/2)))*sin((i+1/2)*((pi*xj)/h))*exp(((-Ha*ko)/(h^2))*((i+1/2)^2)*(pi^2)*t))));
% add the current value of uj to the sum variable
sum = sum + uj;
end
% the final value of sum will be the total summation from n=0 to 3

To vary n from 0-100, you can follow the same approach but change the range of n to 0:100 in the for loop. The code would look like this:

sum = 0; % initialize the sum variable
n = 0:100; % define the range of n
for i = n % loop through each value of n
% calculate the summation equation for the current value of n
uj = (-sig/Ha)*(xj-(((2*h)/(pi^2))*((((-1)^i)/((i+1/2)^(1/2)))*sin((i+1/2)*((pi*xj)/h))*exp(((-Ha*ko)/(h^2))*((i+1/2)^2)*(pi^2)*t))));
% add the current value of uj to the sum variable
sum = sum + uj;
end
% the final value of sum will be the total summation from n=0 to 100
 

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

1. What is the purpose of efficient summation in MATLAB for a biphasic model?

The purpose of efficient summation in MATLAB for a biphasic model is to accurately and efficiently calculate the sum of a large number of terms in a biphasic equation. This is particularly important when the range of n values is large, as it allows for faster and more accurate calculations.

2. How does varying n values from 0-3 to 0-100 affect the efficiency of the summation process?

Varying n values from 0-3 to 0-100 can significantly affect the efficiency of the summation process. When n is small, the summation can be performed quickly and accurately using traditional methods. However, as n increases, the number of terms in the summation also increases, making it more computationally expensive and prone to errors. Using efficient summation techniques in MATLAB can greatly improve the efficiency of the process.

3. What are some common challenges when performing summation in a biphasic model?

Some common challenges when performing summation in a biphasic model include dealing with a large number of terms, managing computational resources, and accurately representing the complex relationships between the terms. These challenges can be overcome by using efficient summation techniques in MATLAB.

4. What are the benefits of using MATLAB for efficient summation in a biphasic model?

MATLAB offers a variety of built-in functions and tools for efficient summation, making it a powerful tool for performing complex calculations in a biphasic model. It also allows for easy manipulation and visualization of data, making it easier to identify and correct errors in the summation process.

5. Can efficient summation techniques in MATLAB be applied to other types of models?

Yes, efficient summation techniques in MATLAB can be applied to other types of models as well. These techniques are not limited to biphasic models and can be used in various scientific and engineering applications where the summation of a large number of terms is required.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
673
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
794
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
862
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Back
Top