Path: news.mathworks.com!not-for-mail
From: "Ahmad " <climber65@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: MATLAB GUI - How to input a function?
Date: Tue, 3 Nov 2009 17:44:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 40
Message-ID: <hcpq52$b99$1@fred.mathworks.com>
Reply-To: "Ahmad " <climber65@gmail.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1257270242 11561 172.30.248.35 (3 Nov 2009 17:44:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 3 Nov 2009 17:44:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2075042
Xref: news.mathworks.com comp.soft-sys.matlab:582107


I have been trying to code Newton Raphson method and while making the GUI which I ran into a problem which is unique for me.

I want to input a function in the form of a polynomial including the x etc so that I can us the following code which I wrote as a very crude and rough example.

syms x
g=x^3-7*x^2+14*x-6;
dg=diff(g,x);
f=sym2poly(g);
df=sym2poly(dg);

a=0;
b=1;
tol=0.01;
itr=2;
itrr=50;

for i=1:itr
p=(a+b)/2;
if(polyval(f,a)*polyval(f,p)<0)
b=p;
else
a=p;
end
end
s=p;

for j=1:itrr
s1=s-polyval(f,s)/polyval(df,s)
if(polyval(f,s)==0|[abs(s-s1)/s]<tol)
break
else
s=s1
end
end

Which functions can I use?

If that is not possible how can I input in the form [1,-7,14,-6] ? My first priority would be to input including x etc if the procedure involved is not too hectic.

Thanks.