Thread Subject: MATLAB GUI - How to input a function?

Subject: MATLAB GUI - How to input a function?

From: Ahmad

Date: 3 Nov, 2009 17:44:02

Message: 1 of 2

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.

Subject: MATLAB GUI - How to input a function?

From: Steven Lord

Date: 3 Nov, 2009 18:07:39

Message: 2 of 2


"Ahmad " <climber65@gmail.com> wrote in message
news:hcpq52$b99$1@fred.mathworks.com...
>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);

*snip*

You can't use POLYVAL with symbolic polynomials directly. Either convert
the symbolic polynomial into a coefficient vector using SYM2POLY and then
use POLYVAL, or evaluate the polynomial directly using SUBS.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com