From: JKA tom on
Hello.
I'm beginner of Numetrical Mathematics.
Now,I'm trying to find a lagrange interpolation polynomial.
Following is the code I made.
================================
px=[1/3 1/4 1];
py=[2 -1 7];
if size(px,2)==size(py,2);
givenx=[1 2];
x=givenx;
n=size(px,2);
l=ones(n,size(x,2));
y=0;
for i=1:1:n
for j=1:1:n
if i~=j
l(i,:)=l(i,:).*(x-px(j))/(px(i)-px(j));
end
end
y=y+py(i)*l(i,:);
end
else
fprintf('not appropriate nodes\n');
end
fprintf('final value is following.\n');
for m=1:1:size(x,2)
fprintf('when x = %f, y= %f\n',x(m), y(m));
end
===============================
This code make me know approximate 'y' value not a interpolating formula.
Any.... Is there a method considering x as a constant not a variables?
for example,
=========
y=1.5*x;
t=x;
=========
when entered the 't' in command window, it is said that x is not defined.
I think...maybe matlab consider x as a variable.
I want to get a '1.5*x' when I enterd the 't' in command window.

I need your help. plz, hlep me.
From: Steven Lord on

"JKA tom" <everjkahn(a)hanmail.net> wrote in message
news:hrrrlc$ckc$1(a)fred.mathworks.com...
> Hello.
> I'm beginner of Numetrical Mathematics.
> Now,I'm trying to find a lagrange interpolation polynomial.
> Following is the code I made.

*snip*

> ===============================
> This code make me know approximate 'y' value not a interpolating formula.
> Any.... Is there a method considering x as a constant not a variables?
> for example,
> =========
> y=1.5*x;
> t=x;
> =========
> when entered the 't' in command window, it is said that x is not defined.
> I think...maybe matlab consider x as a variable.
> I want to get a '1.5*x' when I enterd the 't' in command window.

So you want to treat x as a symbol? Use Symbolic Math Toolbox:

x = sym('x');
y = 1.5*x;
t = y

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