Solutions Curso Matlab
Solutions Curso Matlab
Solutions Curso Matlab
1. Formatos Numéricos
Exercício 1
a)
>> (5+8*3-2)/(4^3*3)
b)
>> sqrt(10-2*32/13)-1/4*10
c)
>> 2^2+sqrt(5-4*1)
Exercício 2
>> x1=-20-sqrt(20^2-4*5*10)
>> x2 = -20 + sqrt(20^2-4*5*10)
Exercício 3
>>format long
>> 1 + 11,5*1/17
>>format short
>> ans
>> format hex
>> ans
>> format rat
>> ans
Exercício 4
>> e = 2.718
>> t = 2018
>> (157273000)/(1+e^(-0.0313*(t-1913.25)))
2. Comandos básicos
Exercício 1
>> h = 15;
>> alfa = 30;
>> A =
((h*sin(degtorad(alfa)))*(h*cos(degtorad(alfa))))/2;
Exercício 2
>> a = round(11.3);
>> b = round(35/3);
>> c = round(-12.5);
>> d = round(52/3);
>> e = round(-16.2);
>> T = a+b+c+d+e+17;
Exercício 3
>> x = degtorad(45);
>> a = x/factorial(1);
>> b = (-1)*(x^3)/factorial(3);
>> c = (x^5)/factorial(5);
>> d = (-1)*(x^7)/factorial(7);
>> s = a+b+c+d;
Exercício 4
>> t = 5;
>> a = log((t^2)+t+2);
>> b = exp(t*(1+cos(3*t)));
>> c = (sec(t))^2+cot(t)-1;
>> t = 10;
>> a2 = log((t^2)+t+2);
>> b2 = exp(t*(1+cos(3*t)));
>> c2 = (sec(t))^2+cot(t)-1;
3. Matrizes e Vetores
Exercício 1
>> v = 15:-5:-25
>> v'
Exercício 2
>> v = linspace(-1,-15,12)
>> v'
Exercício 3
Exercício 5
>> A = eye(7);
>> A(1:2,1:3)=2;
>> A(1:3,5:7)=5;
>> A(3,1:3)=3;
>> A(5:7,1:2)=4;
>> A(5:7,3)=7;
>> A(5:7,5:7)=9;
Exercício 6
>> M=ones(3);
>> B(1:2,1:2)=5;
>> A(1:3,1:3)=M;
>> A(4:5,4:5)=B;
Exercício 7
>> g = 9.81;
>> m = [2, 4, 5, 10, 20, 50];
>> F = [12.5, 23.5, 30, 61, 117, 294];
>> mi = F./(m*g);
4. Polinômios
Exercício 1
>> x=-2:.1:2;
>> y=1.5*x.^3-6*x.^2+x+2;
Exercício 2
5. Números Complexos
Exercício 1
>> x = sqrt(3) + i;
>> m = abs(x);
>> ang = radtodeg(angle(x));
>> y = 4 - 3*i;
>> m = abs(y);
>> ang = radtodeg(angle(y));
>> z = 5*i;
>> m = abs(z);
>> ang = radtodeg(angle(z));
Exercício 2
Exercício 3
>> a = 1;
>> b = 10;
>> c = 20;
>> x1 = (-b+(sqrt(b^2-4*a*c)))/(2*a);
>> x2 = (-b-(sqrt(b^2-4*a*c)))/(2*a);
>> y1 = sqrt(x1);
>> y2 = -sqrt(x1);
>> y3 = sqrt(x2);
>> y4 = -sqrt(x2);
>> r1 = abs(y1);
>> ang1 = angle(y1);
>> r2 = abs(y2);
>> ang2 = angle(y2);
>> r3 = abs(y3);
>> ang3 = angle(y3);
>> r4 = abs(y4);
>> ang4 = angle(y4);
6. Gráficos
Exercício 1
>> x = -50:0.1:50;
>> y = 3*x.^3-26*x+10;
>> plot(x,y);
Exercício 2
>> x=0:0.01:pi;
>> y=sin(x);
>> z=cos(x);
>> plot(x,y,’.’,’color’,’blue’);
>> hold on;
>> plot(x,z,’--’,’color’,’red’);
Exercício 3
>> t=1900:1:2100;
>> P=157273000./(1+exp(-0.0313.*(t-1913.25)));
>> plot(t,P)
Exercício 4
>> t=0:0.01:6*pi;
>> z=t;
>> x=sin(t);
>> y=cos(t);
>> plot3(x,y,z)
7. Comandos de fluxo
Exercício 1
>> A=zeros(6,7)
>> for i = 1:6
>> for j = 1:7
>> if (i>=j)
>> A(i,j)=2*i-3*j;
>> else
>> A(i,j)=sqrt(7*i^2+5*j^2);
>> end
>> end
>> end
>> A
Exercício 2
>> if (MEDIA>=6&FREQUENCIA>=70)
>> fprintf(“Aprovado\n”)
>> else
>> fprintf(“Reprovado\n”)
>> if MEDIA<6&FREQUENCIA>=70
>> fprintf(“Causa: Nota insuficiente\n”)
>> elseif MEDIA<6&FREQUENCIA<70
>> fprintf(“Causa: Nota e frequência insuficientes\n”)
>> else
>> fprintf(“Causa: Frequência insuficiente\n”)
>> end
>> end
Exercício 3
>> V=[9;6;2;3;8;6;4;45;26;9;8;22;6;589;21;7;9];
>> tamanho_de_V=length(V);
>> contador=0;
>> for i=1:tamanho_de_V
>> if rem(V(i,1),2)==0
>> contador=contador+1;
>> end
>> end
>> contador
Exercício 4
>> A=[7;2;1];
>> B=3*A;
>> produto_interno=dot(A,B);
>> a=A/norm(A);
>> b=B/norm(A);
>> if produto_interno==0
>> fprintf(“Os vetores são ortogonais entre si”);
>> end
>> if b==a
>> fprintf(“Os vetores são paralelos entre si”);
>> else
>> C=cross(A,B);
>> c=C/norm(C);
>> end
Exercício 1
letra (a)
>> T=[27.0228 25.4152 23.7288 22.3201 21.4839 21.3796]
>> P=0:.5:2.5
>> p=1.75
>> t=interp1(P,T,p)
letra (b)
>> PolIn=polyfit(P,T,5)
>> t2=polyval(PolIn,p)
letra (c)
>> t2-t
letra (d)
>> tprox=polyval(Polin,3.0)
Exercício 2
Exercício 3
Exercício 4
a)
>> ano = [1940 1950 1960 1970 1980 1990 2000];
>> pop = [537 557 682 826 981 1135 1262];
>> a = polyfit(ano,log(pop),1);
>> pop1955 = exp(a(2))*exp(a(1)*1955);
b)
>> b = polyfit(ano,pop,2);
>> pop1955 = (b(1)*(1955^2))+(b(2)*1955)+(b(3));
c)
>> c1 = spline(ano,pop,1955);
>> c2 = polyfit(ano,pop,1);
>> pop1955 = (c2(1)*1955+c2(2));
Exercício 5
Exercício 2
𝑥 + 𝑦 = 20
{
𝐴 = 𝑥𝑦
𝑦 = 20 − 𝑥
𝐴 = 𝑥(20 − 𝑥 ) = −𝑥 2 + 20𝑥
Exercício 3
𝑥 = √𝑡 3 2 2 3 9
{ 3 ⇒ 𝑑 = √𝑦 2 + 𝑥 2 ⇒ 𝑑 = √(𝑡 2 − ) + ( 𝑡) ⇒ 𝑑 = 𝑡 4 − 𝑡 2 + 𝑡 +
2 √
𝑦=𝑡 − 4 2 16
4
Exercício 4
𝐴𝑐𝑖𝑙𝑖𝑛𝑑𝑟𝑜 = 2𝜋𝑟ℎ
𝐴𝑠𝑒𝑚𝑖𝑒𝑠𝑓𝑒𝑟𝑎 = 4𝜋𝑟 2
𝐴𝑡𝑜𝑡𝑎𝑙 = 𝐴𝑐𝑖𝑙𝑖𝑛𝑑𝑟𝑜 + 𝐴𝑠𝑒𝑚𝑖𝑒𝑠𝑓𝑒𝑟𝑎 = 2𝜋𝑟ℎ + 4𝜋𝑟 2 = 5𝜋 ⇒ ℎ = 2,5 − 2𝑟
2 4
𝑉 = 𝜋𝑟 3 + 𝜋𝑟 2 ℎ ⇒ 𝑉 = − 𝜋𝑟 3 + 2,5𝜋𝑟 2
3 3
10. Derivação
Exercício 1
Letra (a)
>> syms x
>> y=sin(x*(2*x-1))+cos(x*(x^2+1))
>> diff(y,x)
Letra (b)
>> syms t
>> y=8*t*(t^2+3)^3
>> diff(y,t)
Letra (c)
>> syms t
>> y=(2*t+3)/(t^2+3*t+9)
>> diff(y,t)
Exercício 2
>> syms x
>> y=log(x)+1-x^2
>> subs(y,5)
Exercício 3
>> syms a x
>> y=sin(a+2*x)-2*sin(a+x)+sin(a)
>> yy=x^2
>> dy1 = diff(y,x)
>> dy2 = diff(dy1,x)
>> dyy1 = diff(yy,x)
>> dyy2 = diff(dyy1,x)
>> subs((dy2/dyy2),0)
Exercício 4
Letra (a)
>> syms t
>> s=24.5*t-4.9*t^2
>> v=diff(s,t)
>> solve(v==0,t)
>> subs(s,5/2)
Letra (b)
>> syms t
>> s=24.5*t-4.9*t^2
>> solve(s==29.4,t)
>> v=diff(s,t)
>> subs(v,2)
>> subs(v,3)
Exercício 5
>> syms t
>> Q=t^3-2*t^2+6*t+2
>> i=diff(Q,t)
(a)
>> subs(i,0.5)
(b)
>> subs(i,1)
11. Integração
Exercício 1
>> syms x
>> z = 1/(0.8*x^2+0.5*x+2)
>> diff(z,x)
>> int(z,x,0,5)
Exercício 2
a)
>> syms x
>> S=x^3+9*(x^2)+27*x-27;
>> S1=(x+3)^3-x^2-5*x-12;
>> S*S1;
>> subs(ans,x,10)
b)
>> syms x
>> S=x^3+9*(x^2)+27*x-27;
>> S1=(x+3)^3-x^2-5*x-12;
>> S/S1;
>> subs(ans,x,10)
c)
>> syms x
>> S=x^3+9*(x^2)+27*x-27;
>> S1=(x+3)^3-x^2-5*x-12;
>> S+S1;
>> subs(ans,x,10)
d)
>> S*S1
>> [x valor]=fminbnd('-(x^3 + 9*x^2 + 27*x - 27)*(5*x - (x
+ 3)^3 + x^2 + 12)',0,10)
>> [x valor]=fminbnd('-(-(x^3 + 9*x^2 + 27*x - 27)*(5*x -
(x + 3)^3 + x^2 + 12))',0,10)
>> S/S1
>> [x valor]=fminbnd('-(x^3 + 9*x^2 + 27*x - 27)/(5*x - (x
+ 3)^3 + x^2 + 12)',0,10)
>> [x valor]=fminbnd('-(-(x^3 + 9*x^2 + 27*x - 27)/(5*x -
(x + 3)^3 + x^2 + 12))',0,10)
>> S+S1
>> [x valor]=fminbnd('22*x + (x + 3)^3 + 8*x^2 + x^3 -
39',0,10)
>> [x valor]=fminbnd('-(22*x + (x + 3)^3 + 8*x^2 + x^3 -
39)',0,10)
Exercício 3
>> syms x
>> I = exp(2*x)*sqrt(2-exp(2*x))
>> diff(I)
>> int(I)