Search code examples
matlabnumeric

loop function in matlab to repeat a function


I'm a biology student trying to use matlab, my mathematical and informatic knowledge is thereby limited. However I've tried to write some code to obtain the following:

I have a function y=f(t) that describes the growth of every individual. y=f(t) has 8 variables that are constant but are different for each individual. The velocity curve is obtained by differentiating the y=f(t) function. a picture of both the growth and velocity curve can be seen below. The red curve is the growth curve and the blue curve the velocity curve.

the function is described by y(t)= m1*(1-1/(1+(m2*(m0+m8))^m5+(m3*(m0+m8))^m6+(m4*(m0+m8))^m7)). t is here the independent variable. m1 to m8 are variables that are constant for each individual but differ between individuals.

What I would like to obtain is

  • the inflection points (both t and f(t) values) of the growth function
  • the asymptotic value of the growth function
  • the corresponding maximum height of the differentiated function
  • the minimum height of the differentiated function before the maximum height is

    % set variabelen syms t; m1=xlsread('jongens0','A1:A10'); m2=xlsread('jongens0','B1:B10'); m3=xlsread('jongens0','C1:C10'); m4=xlsread('jongens0','D1:D10'); m5=xlsread('jongens0','E1:E10'); m6=xlsread('jongens0','F1:F10'); m7=xlsread('jongens0','G1:G10'); m8=xlsread('jongens0','H1:H10');

    % set loop for i=1:10

    % define function and differentiated function y(i)=m1(i).(1-1./(1+(m2(i).(t+m8(i))).^m5(i)+(m3(i).(t+m8(i))).^m6(i)+(m4(i).(t+m8(i))).^m7(i))); dy(i)=diff(y(i))./dt;

    % information extraction a=max(dy(i)); b=fminsearch(dy(i),x0,[0,a]); c=max(y(i)); d=limit(y(i),inf); e=inflect_pt((y(i)));

    A = [a b c d e]

    % write information to excel xlswrite('output0',A)


Solution

  • You are using incorrect MATLAB syntax.

    for(i=0,t++,i<50)
    

    is closer to C++ syntax than MATLAB. (Although not correct C++ syntax, as pointed out by @John)

    I'm not sure what you are trying to achieve with this code:

    fori=1:50,;
    i;
    end; 
    

    but it's not correct. The , after 1:50 is not supposed to be there. You do not want ; in the end of the for i=1:50 line, nor after end. (; is used to suppress output, and these lines does not produce any)

    It's hard to tell exactly what you want to achieve, but I think something like this is close:

    y = zeros(size(t,1),50);
    
    for i = 1:50
      y(i,:) = m1(i).(1-1./(1+(m2(i).(t+m8(i))).^m5(i) ...
          +(m3(i).(t+m8(i))).^m6(i)+(m4(i).(t+m8(i))).^m7(i)));
    end