Mathematical Modeling and MATLAB MATLAB MATLAB FOR 202134
Mathematical Modeling and MATLAB 数学建模与MATLAB 主讲人:孙越 数学建模与MATLAB 第七讲 FOR循环与二维绘图 2021/3/4
参考答案 for x=1: 30 for y=1: 30 for z=1: 30 if (3*x+2*y+1*z)==50 & (x+y+z)==30 fprintf('有%d个男人,%d个女人,%d个孩子!n', x, y, z); end end 数学建模与MATLAB 10
%算法二 i=0; for x=1: 15 for y=1: 23 for z=1: 28 %算法四 i=i+1; x=input('人数: '); if (3*x+2*y+1*z)==50&(x+y+z)==30 y=input('钱: '); fprintf('有%d个男人,%d个女人,%d个孩子!n', x, y, z); end total=0; end k=0; end for i=1: fix(y/3) end for j=1: fix((y-i*3)/2) fprintf('一共运算了%d次!n', i); if 2*i+j+x==y %算法三 total=total+1; i=0; fprintf('男%d 女%d 小孩%dn', i, j, x-i-j) for x=1: 15 end for y=1: 23 k=k+1; i=i+1; if 3*x+2*y+(30 -x-y)==50 end fprintf('有%d个男人,%d个女人,%d个孩子!n', x, y, (30 -x-y)); end fprintf('一共运算了%d次!n', k); end fprintf('一共运算了%d次!n', i); fprintf('一共有%d组解!n', total); 数学建模与MATLAB 11
plot 函数的调用格式为: • plot(Y) • plot(X 1, Y 1, . . . ) • plot(X 1, Y 1, Line. Spec, . . . ) • plot(. . . , 'Property. Name', Property. Value, . . . ) • plot(axes_handle, . . . ) • h = plot(. . . ) • hlines = plot('v 6', . . . ) 数学建模与MATLAB 15
文字注释 • 格式 text(x, y, ‘string’) %在图形中指定的位置(x, y)上显示 字符串string • 常用Tex字符集 命令 字符 alpha α omega ω Omega Ω eta η beta β psi ψ Psi Ψ rho ρ gamma γ Gamma Γ epsilon ε tau τ delta δ Delta Δ chi χ mu μ theta θ Theta Θ Pi Π pi π sigma σ Sigma Σ zeta ζ xi ξ phi φ Phi Φ oslash nu υ lambda λ Lambda Λ copyright @ infty ∞ forall " leq ≤ pm ± oplus Å 数学建模与MATLAB 31
- Slides: 39