<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264857</link>
    <title>MATLAB Central Newsreader - MATLAB GUI - How to input a function?</title>
    <description>Feed for thread: MATLAB GUI - How to input a function?</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Tue, 03 Nov 2009 17:44:02 -0500</pubDate>
      <title>MATLAB GUI - How to input a function?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264857#691778</link>
      <author>Ahmad </author>
      <description>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.&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
syms x&lt;br&gt;
g=x^3-7*x^2+14*x-6;&lt;br&gt;
dg=diff(g,x);&lt;br&gt;
f=sym2poly(g);&lt;br&gt;
df=sym2poly(dg);&lt;br&gt;
&lt;br&gt;
a=0;&lt;br&gt;
b=1;&lt;br&gt;
tol=0.01;&lt;br&gt;
itr=2;&lt;br&gt;
itrr=50;&lt;br&gt;
&lt;br&gt;
for i=1:itr&lt;br&gt;
p=(a+b)/2;&lt;br&gt;
if(polyval(f,a)*polyval(f,p)&amp;lt;0)&lt;br&gt;
b=p;&lt;br&gt;
else&lt;br&gt;
a=p;&lt;br&gt;
end&lt;br&gt;
end&lt;br&gt;
s=p;&lt;br&gt;
&lt;br&gt;
for j=1:itrr&lt;br&gt;
s1=s-polyval(f,s)/polyval(df,s)&lt;br&gt;
if(polyval(f,s)==0|[abs(s-s1)/s]&amp;lt;tol)&lt;br&gt;
break&lt;br&gt;
else&lt;br&gt;
s=s1&lt;br&gt;
end&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
Which functions can I use?&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
Thanks.</description>
    </item>
    <item>
      <pubDate>Tue, 03 Nov 2009 18:07:39 -0500</pubDate>
      <title>Re: MATLAB GUI - How to input a function?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264857#691784</link>
      <author>Steven Lord</author>
      <description>&lt;br&gt;
&quot;Ahmad &quot; &amp;lt;climber65@gmail.com&amp;gt; wrote in message &lt;br&gt;
news:hcpq52$b99$1@fred.mathworks.com...&lt;br&gt;
&amp;gt;I have been trying to code Newton Raphson method and while making the GUI &lt;br&gt;
&amp;gt;which I ran into a problem which is unique for me.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I want to input a function in the form of a polynomial including the x etc &lt;br&gt;
&amp;gt; so that I can us the following code which I wrote as a very crude and &lt;br&gt;
&amp;gt; rough example.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; syms x&lt;br&gt;
&amp;gt; g=x^3-7*x^2+14*x-6;&lt;br&gt;
&amp;gt; dg=diff(g,x);&lt;br&gt;
&amp;gt; f=sym2poly(g);&lt;br&gt;
&amp;gt; df=sym2poly(dg);&lt;br&gt;
&lt;br&gt;
*snip*&lt;br&gt;
&lt;br&gt;
You can't use POLYVAL with symbolic polynomials directly.  Either convert &lt;br&gt;
the symbolic polynomial into a coefficient vector using SYM2POLY and then &lt;br&gt;
use POLYVAL, or evaluate the polynomial directly using SUBS.&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Steve Lord&lt;br&gt;
slord@mathworks.com&lt;br&gt;
comp.soft-sys.matlab (CSSM) FAQ: &lt;a href=&quot;http://matlabwiki.mathworks.com/MATLAB_FAQ&quot;&gt;http://matlabwiki.mathworks.com/MATLAB_FAQ&lt;/a&gt; </description>
    </item>
  </channel>
</rss>

