I would like to plot the energy level of the 3D rigid body, with Matlab found the following code
clear all
figure
for H=[.01:0.05:0.46 .5 .54:0.05:1.5]
I1=2;I2=1;I3=2/3;
y1=[-1:.0001:0];
y2=sqrt(((2*H-1/I3)-(1/I1-1/I3)*y1.^2)/(1/I2-1/I3));
y3=sqrt(((2*H-1/I2)-(1/I1-1/I2)*y1.^2)/(1/I3-1/I2));
%extract the real solutions y2 and y3:
m=1;
for k=1:length(y1)
if( imag(y2(k))==0 & imag(y3(k))==0 )
y1_new(m) = y1(k);
y2_new(m) = y2(k);
y3_new(m) = y3(k);
m=m+1;
end
end
hold on
if(m>1)
plot3(y1_new,y2_new,y3_new)
plot3(y1_new,-y2_new,y3_new)
plot3(y1_new,y2_new,-y3_new)
plot3(y1_new,-y2_new,-y3_new)
plot3(-y1_new,y2_new,y3_new)
plot3(-y1_new,-y2_new,y3_new)
plot3(-y1_new,y2_new,-y3_new)
plot3(-y1_new,-y2_new,-y3_new)
end
end
However, with Julia I tried the following
using Plots
I1=2;I2=1;I3=2/3;
for H in vcat(.01:0.05:0.46, .5, .54:0.05:1.5)
y1=-1:.0001:0
y2=sqrt.(Complex.(((2 .*H-1/I3).-(1/I1-1/I3) *y1 .^2)/(1/I2-1/I3)));
y3=sqrt.(Complex.(((2 .*H-1/I2).-(1/I1-1/I2) *y1 .^2)/(1/I3-1/I2)));
m=1;
y1_new = [];
y2_new = [];
y3_new = [];
for k = 1:length(y1)
if( imag(y2[k])==0 && imag(y3[k])==0 )
push!(y1_new, y1[k]);
push!(y2_new, y2[k]);
push!(y3_new, y3[k]);
m=m+1;
end
end
if(m>1)
plot3d(y1_new,y2_new,y3_new)
plot3d(y1_new,-y2_new,y3_new)
plot3d(y1_new,y2_new,-y3_new)
plot3d(y1_new,-y2_new,-y3_new)
plot3d(-y1_new,y2_new,y3_new)
plot3d(-y1_new,-y2_new,y3_new)
plot3d(-y1_new,y2_new,-y3_new)
plot3d(-y1_new,-y2_new,-y3_new)
end
end
Using Matlab code, the plot looks like
which I didn’t get with Julia.