1=== test1a.m ============ "hello world" disp ("hello world") 2=== test2a.m ============ a=2.;b=7; c=a+b; disp([num2str(a),'+',num2str(b),'=',num2str(c)]) 3=== test2b.m ============ a=input("enter a="); b=input("enter b="); c=a+b; disp([num2str(a),'+',num2str(b),'=',num2str(c)]) 4=== test2c.m ============ a=load('test2c.in'); c=sum(a); disp(['sum=',num2str(c)]) 5=== test3a.m ============ a=[1,2,3,4,5,6,7]; n=length(a) sum=0 for i =1:n sum=sum+a(i) end disp(['sum=',num2str(sum)]) 6=== test4a.m ============ a=[1,2,3,4,5,6,7]; n=length(a); c=sum(a); disp(['sum=',num2str(c)]) ****************************************** 7=== test4c_mysum.m ============ a=load('test4b.in'); [sum,av]=mysum(a) function [sum,av]=mysum(a) n=length(a); sum=0.; for i=1:n sum=sum+a(i); end av=sum/n; end 8=== test5a.m ============ myfact(0) function [ff]=myfact(n) if n==0||n==1 disp(['fact=1']); return elseif n<0 disp('argument is negativ'); return end ff=1; for i=1:n ff=ff*i; end end 9=== test6a.m ============ [x1,x2,diskr]=myroot(3,3,1) function [x1,x2,diskr]=myroot( a,b,c) diskr=b*b-4*a*c; if(diskr>0) x1=(-b+sqrt(diskr))/(2.*a); x2=(-b-sqrt(diskr))/(2.*a); return end if(diskr==0) x1=-b/(2.*a); return end x1=-b/(2.*a); x2=(sqrt(-diskr))/(2.*a); return end 10=== test7a.m ============ a=[1,2,3]; b=[0,-3,2]; myangle(a,b) function angle=myangle( a,b ) angle=acosd(dot(a,b)/(norm(a)*norm(b))); end 11=== test8a.m ============ a=[1,2,3]; max(a) min(a) 12=== myangle.m ============ function myangle( a,b ) ang=acosd(dot(a,b)/(norm(a)*norm(b))); end 13=== myfact.m ============ function ff=myfact( n ) if n==0||n==1 ff=1; return elseif n<0 disp('argument is negativ'); return end ff=1; for i=1:n ff=ff*i; end return end 14=== plot1.m ============ x=linspace(0,360,100); y1=sind(x); y2=cosd(x); tk=0:30:360; figure ('Name','','Numbertitle','off','Position',[0,0,700,700]) subplot(2,1,1) plot(x,y1) ylabel({'sin'}) xlabel({'angle'}) xticks(tk) grid on subplot(2,1,2) plot(x,y2,'-','Color','black') ylabel({'cos'}) xlabel({'angle'}) xticks(tk) grid on 15=== plot2.m ============ t=0:0.01:100; x=sin(t); y=cos(t); z=t plot3(x,y,z) grid on 16=== plot3_3d.m ============ x=-720:10:720; y=-720:10:720; [X,Y]=meshgrid(x,y); R=sqrt(power(X,2)+power(Y,2)); Z=sind(R); surfc(X,Y,Z) 17=== test10a.m ============ fun = @(x) power(x,2); format long res=integral(fun,0,1) ****************************** 18=== test_11.f90 ============ open(10,file="test11.out") pi=3.1415926536 dx=0.01*pi do i=0,200 x=dx*i write(10,*) x,x*180/pi,sin(x),cos(x),tan(x) enddo stop end 19=== test_11.m ============ y=load('test11.out'); figure ('Name','','Numbertitle','off','Position',[0,0,700,700]) tk=0:30:360; subplot(2,1,1) plot(y(:,2),y(:,3)) ylabel({'sin'}) xlabel({'angle'}) xticks(tk) grid on subplot(2,1,2) plot(y(:,2),y(:,4)) ylabel({'cos'}) xlabel({'angle'}) xticks(tk) grid on