Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!g31g2000vbr.googlegroups.com!not-for-mail
From: Matlab Beginner <matlabeginner@googlemail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Beginner's loop
Date: Sun, 25 Oct 2009 13:48:29 -0700 (PDT)
Organization: http://groups.google.com
Lines: 50
Message-ID: <d228bd22-aa0e-4bc6-9a52-1dfbb168aaf5@g31g2000vbr.googlegroups.com>
NNTP-Posting-Host: 95.224.3.198
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
X-Trace: posting.google.com 1256503709 12228 127.0.0.1 (25 Oct 2009 20:48:29 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sun, 25 Oct 2009 20:48:29 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: g31g2000vbr.googlegroups.com; posting-host=95.224.3.198; 
	posting-account=ROyeAgoAAAAJig7C_99VPxjNVq_-mkhA
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; 
	rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 GTB5,gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:579922


hello everybody.

I am a beginner in matlab and I encounter some problems when
programming loops. I would like to understand what I do wrong and how
can I make it better. I hope there somebody can help me with this.

the problem is the following:

I need to write a function with branches that I need to use afterward
in computing some optimal values.
1. I wrote first a function file for the branching function:

function [c] = c1(x);

for i = 1:size(x)
    if x(i)>=0.5
        c(i) = (x(i)>=0.5)^2;
    else
        c(i) = x(i)-1;
    end
end

in principle I want it to go through all the elements of a vector that
I will give in later and evaluate it using the resp. expression.

2.Testing the function first: when In the main file I write:

x=linspace(-1,10,100)

c1(x)...

it evaluates only x(1)=-1... what am I doing wrong?

3. What I actually need is to use the function in this function file:
(e is a vector of variables e(1) and e(2))

function [firstordcond1, firstordcond2] = nest1seller(e,el,g,mu,b,Bet)

firstordcond2 = c1(e)-((Bet*b*el*(g-b)*((mu*g*e(1))./(mu*g*e(1)+(1-mu)
*b*e(2))-(mu*(1-g*e(1)))./(mu*(1-g*e(1))+(1-mu)*(1-b*e(2))))));
firstordcond1 = c1(2)-((Bet*g*el*(g-b)*((mu*g*e(1))./(mu*g*e(1)+(1-mu)
*b*e(2))-(mu*(1-g*e(1)))./(mu*(1-g*e(1))+(1-mu)*(1-b*e(2))))));
end


could anybody be so kind and help me with this thing?

many many thanks
a matlab beginner