Invalid data for plotting(using a function)

1 view (last 30 days)
AW
AW on 11 Oct 2016
Commented: Walter Roberson on 11 Oct 2016
Hello, I'm trying to plot a function on matlab, I looked up a few answers but none of them work for me.
function f=larange2(func,n)
funky=@(x) (1/(1+x^2));
xi=linspace(-1,1,n);
for i=1:n
yi(i)=func(xi(i));
end
value=1;
zi=linspace(-1,1,100);
l=0;
ziy=[];
valuel=0;
for z=1:100
for i=1:n
value=1;
for c=1:n
if c~=i
value=value*((zi(z)-xi(c))/(xi(i)-xi(c)));
end
if c==n
ziy(z)=(value*yi(i));
end
end
end
end
for i=1:length(ziy)
valuel=valuel+ziy(i);
end
plot(zi,ziy,xi,func);
f=valuel;
end
func is function passed in from another code which is
func=@(x) 1/(1+x^2);
values=larange2(func,3);
SO how do I do this valid, I tried defining the expression in the function itself but that still didn't work.
  1 Comment
Walter Roberson
Walter Roberson on 11 Oct 2016
In your "for c" loop, what is to be done if c == i and c ~= n?

Sign in to comment.

Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!