How to create a function in matlab
2 次查看(过去 30 天)
显示 更早的评论
Hello I need to create a function for finding out the intial values of a logistic map. The logistic map is given by
x(ii+1)=mu*x(ii)*[1-x(ii)]
where all the values lie between the (0,1).
Where x(1) and mu can b found out from the following formulas
x(1)=(S+R1+R2) (mod1)
mu= 3.9+ [((S+R2)(mod1))/10]
where
R1=(k1k2..k6)/(2^23)
R2=(k7k8..k12)/(2^23)
S=(k20k19..k13)/100
Where
K=k1k2...k20 is the key that im going to be using.it is a 20 bit key where each bit has to be accessed for generating R1 R2 and S
I'll be doing this four times for a different key each. So i thought of writng a function that gets the key from the user and performs the sequence generation using logistic map. Please help. thanks in advance.
2 个评论
Stephen23
2015-1-9
Note you should use not name your variables using i or j, as these are the names of the inbuilt imaginary unit .
回答(1 个)
Stalin Samuel
2015-1-9
function [x] = logistic(k)
R1=(k1k2..k6)/(2^23)
R2=(k7k8..k12)/(2^23)
S=(k20k19..k13)/100
x(1)=(S+R1+R2) (mod1)
mu= 3.9+ [((S+R2)(mod1))/10]
x(i+1)=mu*x(i)*[1-x(i)]
end
1 个评论
Stephen23
2015-1-9
When I run this code I get an error as follows:
>> logistic(3)
??? Error: File: logistic.m Line: 2 Column: 9
Unexpected MATLAB operator.
It appears that this code was not tested, as it contains so many bugs and syntax errors. This is not usable MATLAB code:
- referencing variables before they have been defined (eg k1,k2,k6,.etc)
- using ellipses to indicate a range
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!