Invalid data for plotting(using a function)

조회 수: 1 (최근 30일)
AW
AW 2016년 10월 11일
댓글: Walter Roberson 2016년 10월 11일
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
Walter Roberson
Walter Roberson 2016년 10월 11일
In your "for c" loop, what is to be done if c == i and c ~= n?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by