習題
1.R=1k歐姆 c=10^-6 t0=0 plot vc(t) 0=8ms
2.R=1K歐姆 c=1,3,5,7,9,*10^-6 0=8ms程式碼
clear;
r=10^3;
c=[1 3 5 7 9]*10^-6;
t=linspace(0,8,100);
for i=1:5;
w=r*c(i);
v=5*(1-exp(-t/w));
hold on;
plot(t,v),grid on;
hold off;
endUser-defined functions
function [outarg1,outarf2,......] = fname(inarg1,inarg2,....)
(%註解)
(程式碼)
(return 傳回)
end
*使用者定義之檔名
function [x,y] =polar2rect (r,theia)
%
%r -- length of polar vector
%theta -- angle of vector in degree
%x -- x-position
%y -- y-position
%
x = r*cos(theta*pi/180);
y = r*sin (theta*pi/180);
end %function polar2rect習題
寫一個matlab function將直角座標轉成極座標
function name : polar2rect.m程式碼
function rec2polar(x,y)
r=(x^2+y^2)^0.5;
%r=sqrt(x*x+y*y);
t=atan2(y,x)*180/pi;
disp(r);
disp(t);
end 執行
function reg(r1,r2)
if r1 disp('不可輸入小於0之數值')
elseif r1==0 || r2==0
disp(Ɔ')
else
y=(r1*r2)/(r1+r2);
disp(y);
end
end