Please Help me about a great piecewise fun. by matlab 2013a
for k=1,…,n
This is my code.
function p = my_code(x,h) for k=2:length(x) if x >= x(k-1) & x <= x(k-1)+h/3 p(k)=(x(1,:)- x(k-1) ).^3; elseif x>=x(k-1)+h/3 & x<=(x(k-1)+2*h/3) p(k) =1/2+(3 *( x(1,:)- x(k-1)-h )); elseif x >=x(k-1)+2*h/3 & x <= x(k) p(k)=1+(x(1,:)- x(k) ).^2; elseif x >=x(k) & x <= x(k)+h/3 p(k)=1-(x(1,:)- x(k)-h ).^2; elseif x >=x(k)+h/3 & x <= x(k)+2*h/3 p(k) =1/2-(3 *( x(1,:)- x(k)-h )); elseif x >=(x(k)+2*h/3) & x <=x(k+1) p(k) =-(x(1,:)- x(k+1) ).^3; else p(k) = 0; end endend
when run fun. with
h=0.1;x=0:h:1; my_code(x,h)
This is what I'm getting:
ans = 0 0 0 0 0 0 0 0 0 0 0
Also, i have problem about k=1,…,n, because i used form k=2:length(m)
Best Answer