# Math Help - i don't know where is it wrong

1. ## i don't know where is it wrong

plz help me, im newbie in matlab.. ive tried so many ways to make sure it is correct but then still cannot work out..

i hv to do some iteration, and plot as well (save the answer in other place since the answer quite long)

function a = lukis(a0,s,n)

lamda = 1.0*(10e-6);
m = 2;
a(1) = a0;

for i = 1:n
a(i+1) = a(i) + lamda * a(i).^(m/2) * s.^m

if(a(i+1)>1)
break;
end
end
plot(a(i+1))

hold on

save('lukis', 'a(i+1)')

to run in c/w : lukis(1.0*10e-10,0.5,1000)

thanks.

2. Originally Posted by anizatie
plz help me, im newbie in matlab.. ive tried so many ways to make sure it is correct but then still cannot work out..

i hv to do some iteration, and plot as well (save the answer in other place since the answer quite long)

function a = lukis(a0,s,n)

lamda = 1.0*(10e-6);
m = 2;
a(1) = a0;

for i = 1:n
a(i+1) = a(i) + lamda * a(i).^(m/2) * s.^m

if(a(i+1)>1)
break;
end
end
plot(a(i+1))

hold on

save('lukis', 'a(i+1)')

to run in c/w : lukis(1.0*10e-10,0.5,1000)

thanks.
Code:
function a = lukis(a0,s,n)

lamda = 1.0*(10e-6);
m = 2;
a=zeros(1,n);
a(1) = a0;

for i = 1:n-1
a(i+1) = a(i) + lamda * a(i).^(m/2) * s.^m

if(a(i+1)>1)
break;
end
end

plot(a(i+1))

hold on

save('lukis', 'a')
CB

3. Originally Posted by CaptainBlack
Code:
function a = lukis(a0,s,n)

lamda = 1.0*(10e-6);
m = 2;
a=zeros(1,n);
a(1) = a0;

for i = 1:n-1
a(i+1) = a(i) + lamda * a(i).^(m/2) * s.^m

if(a(i+1)>1)
break;
end
end

plot(a(i+1))

hold on

save('lukis', 'a')
CB

thanks for your reply. its helping me a lot but when the value of a(i+1)>1, the operation still go on, the iterations should stop when a(i+1) reach 1.

by looking at the program, it seem notin wrong there.. hope u can help me.. thanks.

4. i have found another way to solve this problem... thank you.