Using a array in a equation that has a variable being isolated.
이전 댓글 표시
I've been assigned to use MatLab to make a graph of the height a projectile is released from a ramp vs the distance it travels. As far as i know i have everything required but isolating t as a function of several other functions including the array h. No mater what I do I still get the error message "Matrix dimension must agree". Can anyone help?
clc
%Setting heights and velocity equations
%h=height,g=gravity,v=velocity
%vx=horizontal velocity,vy=vertical velocity
g=9.8;
h=[0.1:0.1:1];
v=sqrt(2*g*h);
vy=v*sind(45);
vx=v*cosd(45);
%defining t
%yp=vertical displacement against time
%h=height
y = ((h+(vy.*t))-(.5.*g.*t.^2) == 0);
t = solve(y,t);
%finding range
%r=range
r=vx.*t;
%Making a graph based of height against range
plot(h,r)
xlabel('height')
ylabel('range')
댓글 수: 2
John D'Errico
2017년 9월 2일
Are there two solutions to that quadratic equation? Solve will give them both to you.
John McClarin
2017년 9월 2일
답변 (2개)
Star Strider
2017년 9월 1일
Try this:
g=9.8;
h=[0.1:0.1:1];
v=sqrt(2*g*h);
vy=v*sind(45);
vx=v*cosd(45);
%defining t
%yp=vertical displacement against time
%h=height
for k1 = 1:numel(h)
y = @(t) (h(k1)+(vy.*t))-(.5.*g.*t.^2);
t(k1) = fsolve(y, 1);
end
%finding range
%r=range
r=vx.*t;
%Making a graph based of height against range
plot(h,r)
xlabel('height')
ylabel('range')
댓글 수: 4
John McClarin
2017년 9월 1일
Star Strider
2017년 9월 2일
It worked when I ran it or I’d not have posted the code.
John McClarin
2017년 9월 2일
Star Strider
2017년 9월 2일
Did my Answer solve your problem?
Image Analyst
2017년 9월 1일
0 개 추천
See my projectile demo. It computes and plots just about everything you could want. Here are the plots. Other info is given in message boxes.


Adapt as needed.
댓글 수: 3
John McClarin
2017년 9월 2일
Image Analyst
2017년 9월 2일
I don't understand. What is the "a array"? And why is it not a variable? And why is c, which is y0 = the initial height, an array? "a" and "c" in my code are scalars. Post your new code.
John McClarin
2017년 9월 2일
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!