n=2 # 2nd/4th order of polynomial
dt=1/50
t=-1:dt:1
y=zeros(size(t))
for i=0:n
for dt=1:size(t,2)
y(dt)=Bernstein(n,i,t(dt))
end
plot(t,y, reuse=false)
end #xlabel(“X’); ylabel('Y”)
The y(dt) = ... is function declaration syntax in julia, instead use y[dt] = .... I am not familiar with PyPlot but usually if you want hold on MATLAB behaviour , you can use plot!(...) for later plots after first plot in julia plot libraries.
I have changed the codes (plot!) as the following:
function Bernstein(n,i,t)
Brnbasis=factorial(BigInt(n))/factorial(BigInt(i))/factorial(BigInt(n-i)) (1/2+t/2)^i (1/2-t/2)^(n-i)
return(Brnbasis)
end
#using PyPlot
using Plots
pyplot()
n=2 # 2nd/4th order of polynomial
dt=1/50
t=-1:dt:1
y=zeros(size(t))
for i=0:n
for dt=1:size(t,1)
y[dt]=Bernstein(n,i,t[dt])
end
plot!(t,y)
end #xlabel(“X’); ylabel('Y”)
In Julia, PyPlot will hold on automatically. Just use the correct syntax for indexing and function call.
function Bernstein(n,i,t)
Brnbasis=factorial(BigInt(n))/factorial(BigInt(i))/factorial(BigInt(n-i)) #(1/2+t/2)^i(1/2-t/2)^(n-i)
return(Brnbasis)
end
using PyPlot
n = 2 # 2nd/4th order of polynomial
dt = 1/50
t = -1:dt:1
y = zeros(size(t))
for i = 0:n
for dt = 1:size(t,2)
y[dt] = Bernstein(n,i,t[dt])
end
plot(t,y)
end
xlabel("X"); ylabel("Y")