%I dont know why does it marks an error on line 52 (it is commented)
clear all;
clc;
g=9.8;
opcion=1;
while opcion ~=0
fprintf('\n\nMenú de opciones');
fprintf('\n\t1. Animacion de tres tiros parabolicos');
fprintf('\n\t2. Determinación de condiciones para alcanzar una distancia dada por el usuario.');
fprintf('\n\t3. Tiro parabólico con parámetros del usuario.' )
fprintf('\n\t0. Salir');
opcion=input('\n\nEscribe tu opcion: ');
area=0;
switch opcion
case 1
Vo=150;
Ang1 = 23;
Ang2 = 24;
Ang3 = 25;
Ai = 5200;
Ang1 = Ang1*3.1416/180;
Ang2 = Ang2*3.1416/180;
Ang3 = Ang3*3.1416/180;
ta = ( ((Vo*sin(Ang1))+(Vo*sin(Ang1))^2+2*Ai*g)^0.5)/g;
tb = ( ((Vo*sin(Ang2))+(Vo*sin(Ang2))^2+2*Ai*g)^0.5)/g;
tc = ( ((Vo*sin(Ang3))+(Vo*sin(Ang3))^2+2*Ai*g)^0.5)/g;
xmax1 = Vo*cos(Ang1)*ta;
xmax2 = Vo*cos(Ang2)*tb;
xmax3 = Vo*cos(Ang2)*tc;
ymax1 = ((Vo*sin(Ang1))^2)/(2*g);
ymax2 = ((Vo*sin(Ang2))^2)/(2*g);
ymax3 = ((Vo*sin(Ang3))^2)/(2*g);
t1 = 0:0.05:ta;
t2 = 0:0.05:tb;
t3 = 0:0.05:tc;
ya = (Vo*sin(Ang1)).*t1-(0.5*g).*(t1.^2)+Ai;
yb = (Vo*sin(Ang2)).*t2-(0.5*g).*(t2.^2)+Ai;
yc = (Vo*sin(Ang3)).*t3-(0.5*g).*(t3.^2)+Ai;
xa = Vo*cos(Ang1).*t1;
xb = Vo*cos(Ang2).*t2;
xc = Vo*cos(Ang3).*t3;
%Marca error por arrays incompatibles :(
y2a = (tan(Ang1).*xa)-(0.5*g/(Vo*cos(Ang1))^2).*(x.^2)+Ai;
y2b = (tan(Ang2).*xb)-(0.5*g/(Vo*cos(Ang2))^2).*(x.^2)+Ai;
y2c = (tan(Ang3).*xc)-(0.5*g/(Vo*cos(Ang3))^2).*(x.^2)+Ai;
%arreglo diferente
for i = 1:0.5:xmax1
y3a= Ai + (tan(Ang1).*i)-(0.5*g/(Vo*cos(Ang1))^2)*(i.^2);
hold on ;
pause(0.01);
I = imread('Ejemplo volcan.jfif');
ha = image(xlim,(ymax1+Ai-ylim),I);
uistack(h,'bottom')
pause(0.1);
plot(i,y3a,'b*','MarkerSize',8,'LineWidth',2)
title('Grafica Y vs t')
xlabel('Distancia')
ylabel('y(m)')
axis([0 xmax1 0 ymax1+Ai]);
end
for i2 = 1:0.5:xmax2
y3b= Ai + (tan(Ang2).*i2)-(0.5*g/(Vo*cos(Ang2))^2)*(i2.^2);
hold on ;
pause(0.01);
I = imread('Ejemplo volcan.jfif');
hb = image(xlim,(ymax2+Ai-ylim),I);
uistack(h,'bottom')
pause(0.1);
plot(i2,y3b,'b*','MarkerSize',8,'LineWidth',2)
title('Grafica Y vs t')
xlabel('Distancia')
ylabel('y(m)')
axis([0 xmax2 0 ymax2+Ai]);
end
for i3 = 1:0.5:xmax3
y3c= Ai + (tan(Ang3).*i3)-(0.5*g/(Vo*cos(Ang3))^2)*(i3.^2);
hold on ;
pause(0.01);
I = imread('Ejemplo volcan.jfif');
hc = image(xlim,(ymax3+Ai-ylim),I);
uistack(h,'bottom')
pause(0.1);
plot(i3,y3c,'b*','MarkerSize',8,'LineWidth',2)
title('Grafica Y vs t')
xlabel('Distancia')
ylabel('y(m)')
axis([0 xmax3 0 ymax3+Ai]);
end
case 2
%casinho dos
case 3
Vo=input("ingrese velocidad inicial: ");
if Vo > 200
Vo = input("ingrese un dato de velocidad valido entre 1 y 200");
end
Ang = input("angulo del proyectil: ");
Ai = input("Altura inicial: ");
Ang = Ang*3.1416/180;
t = ( ((Vo*sin(Ang))+(Vo*sin(Ang))^2+2*Ai*g)^0.5)/g;
xmax = Vo*cos(Ang)*t;
ymax = ((Vo*sin(Ang))^2)/(2*g);
t1 = 0:0.05:t;
y = (Vo*sin(Ang)).*t1-(0.5*g).*(t1.^2)+Ai;
x = Vo*cos(Ang).*t1;
y2 = (tan(Ang).*x)-(0.5*g/(Vo*cos(Ang))^2).*(x.^2)+Ai;
for i = 1:0.5:xmax
y3= Ai + (tan(Ang).*i)-(0.5*g/(Vo*cos(Ang))^2)*(i.^2);
hold on ;
pause(0.01);
I = imread('Ejemplo volcan.jfif');
h = image(xlim,(ymax+Ai-ylim),I);
uistack(h,'bottom')
pause(0.1);
plot(i,y3,'b*','MarkerSize',8,'LineWidth',2)
title('Grafica Y vs t')
xlabel('Distancia')
ylabel('y(m)')
axis([0 xmax 0 ymax+Ai]);
end
otherwise
if opcion~=0
fprintf('\n Opción no valida ingrese otro dato:');
end
end
end

댓글 수: 2

dpb
dpb 2022년 10월 13일
편집: dpb 2022년 10월 13일
Too much code; no way to run it, no idea which line might be 52; didn't post error message, ...
Use the debugger -- set
dbstop if error
Valente
Valente 2022년 10월 14일
Thanks

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2022년 10월 14일

0 개 추천

case 1
%...
t1 = 0:0.05:ta;
t2 = 0:0.05:tb;
t3 = 0:0.05:tc;
Those t1, t2, t3 are going to different lengths depending on what ta tb tc calculated out as.
xa = Vo*cos(Ang1).*t1;
xb = Vo*cos(Ang2).*t2;
xc = Vo*cos(Ang3).*t3;
So xa, xb, xc are going to be different lengths
%Marca error por arrays incompatibles :(
y2a = (tan(Ang1).*xa)-(0.5*g/(Vo*cos(Ang1))^2).*(x.^2)+Ai;
y2b = (tan(Ang2).*xb)-(0.5*g/(Vo*cos(Ang2))^2).*(x.^2)+Ai;
y2c = (tan(Ang3).*xc)-(0.5*g/(Vo*cos(Ang3))^2).*(x.^2)+Ai;
x is undefined at that point, **unless* case 3 has already been executed.
case 3
%...
t1 = 0:0.05:t;
t1 is going to vary in size depending on what angles the user entered for option 3
x = Vo*cos(Ang).*t1;
so x is going to vary in size according to the angles entered.
Then, assuming that the user choose option 3 before option 1 so that x does get defined in time, back in case 1
y2a = (tan(Ang1).*xa)-(0.5*g/(Vo*cos(Ang1))^2).*(x.^2)+Ai;
x is a size depending on the angles the user entered for case 3, and xa is a size depending on the calculations for t1, and those are unlikely to be the same length. The (tan(Ang1).*xa) part will end up one length, and the (0.5*g/(Vo*cos(Ang1))^2).*(x.^2) part will end up what is likely to be a different length, making it impossible to subtract the two.
But... .your code never uses y2a, y2b, or y2c after you calculate them, so it is not clear why you bother to calculate them.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Calendar에 대해 자세히 알아보기

제품

릴리스

R2022b

질문:

2022년 10월 13일

댓글:

2022년 10월 17일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by