function [x,y] = butterfly_function(tmin,tmax,dt,s,x0,y0)
%BUTTERFLY_FUNCTION Summary of this function goes here
% Detailed explanation goes here
t=tmin:dt:tmax;
f=exp(cos(t))-2*cos(4*t)-(sin(t/12)).^5;
x=x0+(s.*f.*sin(t));
y=y0+(s.*f.*cos(t));
end
---------------------------------
Matlab code for main program
-----------------
tmin=0;
tmax=40*pi;
dt=0.001;
s=0.1;
x0=1;
y0=1;
[x,y] = butterfly_function(tmin,tmax,dt,s,x0,y0);
plot(x,y,'b')
axis([0 4 0 4])
axis equal
hold on
s=0.4;
x0=2.5;
y0=1;
[x,y] = butterfly_function(tmin,tmax,dt,s,x0,y0);
plot(x,y,'r')
hold on
s=0.2;
x0=0.5;
y0=3;
[x,y] = butterfly_function(tmin,tmax,dt,s,x0,y0);
plot(x,y,'k')
hold on

 採用された回答

Geoff Hayes
Geoff Hayes 2016 年 11 月 5 日
編集済み: Geoff Hayes 2016 年 11 月 5 日

0 投票

ASA - I suppose if it is the main part of your code that you wish to iterate/loop over, you could do something like
tmin=0;
tmax=40*pi;
dt=0.001;
s = [0.1 0.4 0.2];
x0 = [1 2.5 0.5];
y0 = [1 1 3];
c = {'b', 'r','k'};
for k=1:length(s)
[x,y] = butterfly_function(tmin,tmax,dt,s(k),x0(k),y0(k));
plot(x,y,c{k})
hold on
end
Try the above and see what happens! Note how the code just takes those elements that are variable and creates arrays out of them. We then iterate over each element in the array to call the butterfly_function.

その他の回答 (0 件)

カテゴリ

タグ

タグが未入力です。

質問済み:

ASA
2016 年 11 月 5 日

コメント済み:

ASA
2016 年 11 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by