Results 1 to 2 of 2

Math Help - 2 returns in matlab function

  1. #1
    Newbie
    Joined
    Sep 2009
    Posts
    2

    Question 2 returns in matlab function

    I am writing two function, one to solve a system of nonlinear equations using jacobi's method, and one to find the most efficient relaxation it. My problem is that I want to pass two values from the first code (jacobi) to the second code (plotter), But I can only figure out how to send on. I would really appreciate any help. Here is the first pare of my Jacobi code (requires 4 input) and my plotter code:

    function [bad,count]=jacobi(x1,x2,x3,w)

    re=10^(-3); %Relative Error Tolerance
    rt=10^(-3); %Risidual Tolerance
    maxi=400; %Maximum Iteration
    count=1; rele=re+1; res=rt+1; %Counter , reletive error, and residual
    bad=0; %Boolean to pass to the plotter if it diverges

    %%%%%%%%A bunch of code that I don't really think matters for this is here%%%%%%%%%

    if rele >= 100 %Breaks loop if the values are diverging
    disp('The relaxation is bad, try again');
    count = 400;
    bad=1;
    break
    end




    function plotter(x1,x2,x3)
    k=1;
    for(w=0.01:0.002:0.6)
    count=jacobi(x1,x2,x3,w);
    curveJ(k,2)=count; %number of iterations required
    curveJ(k,1)=w; %relaxation factor
    k=k+1;
    bad=jacobi(bad);
    if(bad==1)
    break
    end

    end
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Member
    Joined
    Mar 2007
    Posts
    206
    Awards
    1
    In the plotter function try:

    Code:
    [bad, count]= jacobi(x1,x2,x3,w);
    previously you only had:

    Code:
    count=jacobi(x1,x2,x3,w);
    But as you can see in your definition of the "jacobi" function the first output is actually "bad" so as a result you were really assigning the output bad to the variable name "count" which I dont think is what you want to do. Try the recomendation about and see how you go.

    Elbarto
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. question on calculating returns
    Posted in the Business Math Forum
    Replies: 0
    Last Post: November 30th 2011, 07:00 PM
  2. TI-89 returns the series I entered
    Posted in the Calculators Forum
    Replies: 2
    Last Post: April 15th 2011, 11:19 PM
  3. Banking, interest rates, returns, etc....
    Posted in the Business Math Forum
    Replies: 0
    Last Post: October 14th 2010, 04:52 AM
  4. Geometric linking of returns
    Posted in the Business Math Forum
    Replies: 2
    Last Post: December 23rd 2009, 08:28 PM
  5. Replies: 2
    Last Post: March 22nd 2009, 12:48 AM

Search Tags


/mathhelpforum @mathhelpforum