필터 지우기
필터 지우기

Help with 3D-plotting?

조회 수: 1 (최근 30일)
Lewis Hancox
Lewis Hancox 2018년 3월 14일
댓글: Star Strider 2018년 3월 14일
So I have made this code that creates the shape I desire, but the top is open, and I want it to flat on the top. Any help would be appreciated. Thanks
if true
% code
end
%Constants
A=7/4;
L=1;
R=1;
%Solve for u_2
syms u
u_2=vpasolve(u*(-A-log(u)+u^2+3*u^4/4)*(1+u^2)^(-2)== L/R, u)
%x(u_2)=R rearranges to get C=...,
C=R*u_2/(1+u_2^2)^2
syms u
u_1=vpasolve(-log(u)+u^2+3*u^4/4 == A, u)
x_1=(C*(1+u_1^2)^2)/u_1
v= linspace (u_1,u_2);
X= C*((1+v.^2).^2)./v;
Y= L-C*(-A-log(v)+v.^2+(3*v.^4)/4);
plot(X,Y)
figure(1)
figure(2)
u1 = double(u_1)
u2 = double(u_2)
syms r v
colormap(bone)
x=fsurf(cos(r)*C*((1+v.^2).^2)./v, sin(r)*C*((1+v.^2).^2)./v,(L-C*(-A-log(v)+v.^2+(3*v.^4)/4)),[0,2*pi u1, u2])
title('R=1 L=1')

채택된 답변

Star Strider
Star Strider 2018년 3월 14일
Tweak figure(2) by adding a patch call:
figure(2)
u1 = double(u_1)
u2 = double(u_2)
syms r v
colormap(bone)
x=fsurf(cos(r)*C*((1+v.^2).^2)./v, sin(r)*C*((1+v.^2).^2)./v,(L-C*(-A-log(v)+v.^2+(3*v.^4)/4)),[0,2*pi u1, u2])
hold on
rv = linspace(0,2*pi);
Radius = 0.35;
patch(Radius*cos(rv), Radius*sin(rv), ones(size(rv)), 'r') % <— ADD THIS ‘patch’ CALL, REFINE ‘Radius’
hold off
title('R=1 L=1')
I don’t know how you define the value for the radius of the top, so I guessed at one that sort of works. Tweak that, change the colour to something you want, and it should work. See the documentation for patch to tweak its properties.
  댓글 수: 2
Lewis Hancox
Lewis Hancox 2018년 3월 14일
Thanks again! I can't get the colormap to work on the patch, but I'll just make it all one colour I suppose.
Star Strider
Star Strider 2018년 3월 14일
As always, my pleasure!
I’m not sure what to advise with respect to the colormap. That you’re using symbolic calculations and fplot makes that something of a challenge. Experiment using the last row of the colormap for the patch object colour. It could work!

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

추가 답변 (2개)

Lewis Hancox
Lewis Hancox 2018년 3월 14일
Sorry to bug you again, but when I change the height the patch doesn't sit on top properly. I've changed the code so the radius matched but I can't get it to sit on correctly. Thanks again
if true
% code
end
%Constants
u1=1; %Assume minimum occurs here
L=1/2;
R=1;
%Solve for u_2
syms A
A=-log(u1)+u1^2+3*u1^4/4
syms u2
u2=vpasolve(u2*(-A-log(u2)+u2^2+3*u2^4/4)*(1+u2^2)^(-2)== L/R, u2)
C=u2*R/(1+u2^2)^2
x1=C*((1+u1^2)^2)/u1
u= linspace (u1,u2);
X= C*((1+u.^2).^2)./u;
Y= L-C*(-A-log(u)+u.^2+(3*u.^4)/4);
plot(X,Y)
figure(1)
figure(2)
u_1 = double(u1)
u_2 = double(u2)
syms r u
x=fsurf(cos(r)*C*((1+u.^2).^2)./u, sin(r)*C*((1+u.^2).^2)./u,(L-C*(-A-log(u)+u.^2+(3*u.^4)/4)),[0,2*pi u_1, u_2],'b')
title('R=1 L=5')
figure(2)
u1 = double(u_1)
u2 = double(u_2)
x_1=double(x1)
syms r v
colormap(autumn)
x=fsurf(cos(r)*C*((1+u.^2).^2)./u, sin(r)*C*((1+u.^2).^2)./u,(L-C*(-A-log(u)+u.^2+(3*u.^4)/4)),[0,2*pi u1, u2])
hold on
rv = linspace(0,2*pi);
Radius = x_1;
patch(Radius*cos(rv), Radius*sin(rv), ones(size(rv)),'y')
% <— ADD THIS ‘patch’ CALL, REFINE ‘Radius’
hold off
title('R=1 L=1')

Lewis Hancox
Lewis Hancox 2018년 3월 14일
Actually no worries worked it out. Did L*ones(...)
  댓글 수: 1
Star Strider
Star Strider 2018년 3월 14일
Good!
It likely would have been best for me to gave included that option, specifying a multiplier. It didn’t seem necessary originally.

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

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by