Matlab help!! compute grosper curve
Maths and statistics discussion, revision, exam and homework help.
-
Matlab help!! compute grosper curve
Gosper curve, 4 steps
Axiom: XF
Production rules:
Newx=X+YF++YF-FX- - FXFX-YF+
Newy=-FX+YFYF+ + YF+FX- - FX-Y
Constants: alpha=0; θ=pi/3
The following is what I have done so far. However there is a problem of my matlab code, which is not a correct graph for Gosper curve, which is not matched to the Gosper curve in wikipedia. Many anyone help me to check the mistake please? Many thanks for helping!!
function [X,Y]=Gosper_curve(Lmax)
Axiom='XF';
Newf='F';
Newx='X+YF++YF-FX--FXFX-YF+';
Newy='-FX+YFYF++YF+FX--FX-Y';
theta=pi/3;
alpha=0;
p=[0;0];
p=Coord(p,Lmax,Axiom,Newf,Newx,N ewy,alpha,theta);
M=size(p,2);
X=p(1:1,1:M);
Y=p(2:2,1:M);
figure(1);
plot(X,Y,'Color','k');
set(gca,'xtick',[],'ytick',[]);
set(gca,'XColor','w','YColor','w ');
function z=Coord(p,Lmax,Axiom,Newf,Newx,N ewy,alpha,theta)
Rule=Gosper_syst(Lmax,Axiom,Newf ,Newx,Newy,1,'');
M=length(Rule);
for i=1:M
Tmp=p(1:2,size(p,2):size(p,2));
if Rule(i)=='F'
R=[cos(alpha);sin(alpha)];
R=R/(2^Lmax);
Tmp=Tmp+R;
p=cat(2,p,Tmp);
end
if Rule(i)=='+'
alpha=alpha+theta;
end
if Rule(i)=='-'
alpha=alpha-theta;
end;
end
z=p;
function z1=Gosper_syst(Lmax,Axiom,Newf,N ewx,Newy,n,tmp)
if n<=Lmax
if n==1
tmp=Axiom;
end
M=length(tmp);
tmp1='';
for i=1:M
if tmp(i)=='F'
tmp1=strcat(tmp1,Newf);
end
if tmp(i)=='X'
tmp1=strcat(tmp1,Newx);
end
if tmp(i)=='Y'
tmp1=strcat(tmp1,Newy);
end
if not(tmp(i)=='F') &¬(tmp(i)=='X') &¬(tmp(i)=='Y')
tmp1=strcat(tmp1,tmp(i));
end
end
tmp=tmp1;
n=n+1;
tmp=Gosper_syst(Lmax,Axiom,Newf, Newx,Newy,n,tmp);
end
z1=tmp; -
Matlab help!! compute grosper curve
It's been a while since you posted and nobody's replied yet...maybe you should check out MarkedbyTeachers.com, TSR's sister site. It has the largest library of essays in the UK.
They've got over 181,000+ coursework, essays, homeworks etc.. all written by GCSE, A Level, University and IB students across all topics. You get access either by publishing some of your own work, or paying £4.99 for a month's access. Both ways give you unlimited access to all of the essays.
All their documents are submitted to Turnitin anti-plagiarism software, so it can't be misused, and the site's used by hundreds of thousands of UK teachers and students.
What's more, you can take a look around the site and preview the work absolutely free. Click here to find out more...