How do I write this script as a function? Here is the code for a simple Matlab s
ID: 643836 • Letter: H
Question
How do I write this script as a function?
Here is the code for a simple Matlab script that will generate a Julia Set plot:
Simple Julia Set Script:
maxstep=30; m=400; % m = size of plot grid
cx=0; cy=0; %center of a rectangle
wid=1.5; % width of sides of rectangle
x=linspace(cx-wid,cx+wid,m);
y=linspace(cy-wid,cy+wid,m);
[X,Y]=meshgrid(x,y);
c1=-.75; c2= .375+.333*1i; c3= -.117-.856*1i;
c=c1; %choose one of the above
%c= -.745429;
Z=X+1i*Y;
for k=1:maxstep;
Z=Z.^2+c;
W=exp(-abs(Z));
end
colormap prism(256)
pcolor(W);
shading flat;
1) Convert the above script into a function that will take 4 arguments for c, maxstep, m and wid. Save the function as juliaF.m Be sure to follow the recommended Matlab format for functions and add comments to document what the function does.
2) Add an X label to the resulting plot that shows the value of c used for generating the plot (see below.) You will need to use string handling functions to accomplish this.
Explanation / Answer
function void = juliaF(c, maxstep, m, wid ) clc; maxstep=30; m=400; % m = size of plot grid cx=0; cy=0; %center of a rectangle wid=1.5; % width of sides of rectangle x=linspace(cx-wid,cx+wid,m); y=linspace(cy-wid,cy+wid,m); [X,Y]=meshgrid(x,y); c1=-.75; c2= .375+.333*1i; c3= -.117-.856*1i; c=c1; %choose one of the above %c= -.745429; Z=X+1i*Y; for k=1:maxstep; Z=Z.^2+c; W=exp(-abs(Z)); end colormap prism(256) pcolor(W); shading flat;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.