Documente Academic
Documente Profesional
Documente Cultură
I)
1. Siruri numerice
Exercitiul #1
n=1:100; plot(n,(1+(1./n)).^n,'*')
>>n=1;x=abs((1+(1./n)).^n-exp(1));
>>while x>.001 n=n+1; x=abs((1+(1./n)).^n-exp(1));end
>>while x>.001 n=n+1; x=abs((1+(1./n)).^n- exp(1));endwhile
OCTAVE
% varianta
>>[n]
ans = 1359
Al 1359-lea termen aproximeaz cu dou zecimale numrul e :
n=1359;y=(1+(1./n)).^n
y=
2.7173
Exercitiul #2
n=1:30;plot(n,(n.^2+1)./3.^n,'*')
Exercitiul #3
n=1;x=norm([(2.*n-1)./(n.^2+5),(n.^4-1)./(n.^4+8),(n.^3)./(5.^n)]-
[0,1,0]);while x>0.001
n=n+1; x=norm([(2.*n-1)./(n.^2+5),(n.^4-1)./(n.^4+8),(n.^3)./(5.^n)]-
[0,1,0]);end
n=1;x=norm([(2.*n-1)./(n.^2+5),(n.^4-1)./(n.^4+8),(n.^3)./(5.^n)]-
[0,1,0]);while x>0.001
n=n+1; x=norm([(2.*n-1)./(n.^2+5),(n.^4-1)./(n.^4+8),(n.^3)./(5.^n)]-
[0,1,0]);endwhile
% Varianta OCTAVE
[n]
ans =
2000
Aadar 1999 termeni ai irului nu aparin bilei.
II) CICLUL CU TEST INITIAL (repetarea unei operatii atata timp cat o
anumita conditie este indeplinita) for
>> for var = expression
body
endfor
>>
>>
Alte exemple
MATLAB SYMBOLIC
Exercitiul #1
syms x
n=1;s=-(x^2)/(1+x^4);while n<50 n=n+1; s=s+((-1)^n)*x^2/(n^4+x^4);end
ezplot(s,-5,5)
x^2/(14641+x^4)+x^2/(20736+x^4)+x^2/(1679616+x^4)x^2/(28561+x^4)+x^2/(38416+x^4)-x^2/(50625+x^4)x^2/(5764801+x^4)+x^2/(65536+x^4)+x^2/(5308416+x^4)x^2/(83521+x^4)+x^2/(104976+x^4)-x^2/(4879681+x^4)x^2/(130321+x^4)+x^2/(160000+x^4)x^2/(194481+x^4)+x^2/(4477456+x^4)+x^2/(234256+x^4)x^2/(279841+x^4)+x^2/(331776+x^4)-x^2/(390625+x^4)+x^2/(456976+x^4)x^2/(531441+x^4)+x^2/(614656+x^4)x^2/(707281+x^4)+x^2/(6250000+x^4)+x^2/(810000+x^4)x^2/(923521+x^4)+x^2/(1048576+x^4)-x^2/(1185921+x^4)+x^2/(1336336+x^4)x^2/(1500625+x^4)-x^2/(2313441+x^4)
Exercitiul #2