How do I input the y-coordinate as a variable in Matlab?

I have to input a function where the output is reliant on the y-axis coordinate
Uwind = -75*(1-((75-y)/75)^2)
Is there any way that i can make the y value the y coordinate at any given point along the x axis?

Answers (1)

syms y
Uwind = -75*(1-((75-y)/75)^2)
fplot(Uwind)
is this what you are looking for ? if not let know

7 Comments

I don't think this is it. Later in my code when I use an i loop I get an error message saying that it can't convert the syms value to double form
That’s why I told you upload the full code
m=0.05 %kg
A=pi*(.03)^2 %m^2
C=0.8
U=50 %m/s
density= 1.183 %kg/m^3
D=0.5*density*C*A^2*sign(U) %N
g=9.81 %m/s^2
theta=25 %deg
Uwind = -75*(1-((75-y)/75)^2) %m/s
%Initial Conditions
dt= 0.001 %s
x(1)=0
y(1)=50
x2(1)=0
y2(1)=50
vx=U*cosd(theta)
vy=U*sind(theta)
vx2=U*cosd(theta)
vy2=U*sind(theta)
t(1)=0
t2(1)=0
%Start Loop
i=1
while min(y2)> -.001
ay2=-g;
ax2=0.0;
vx2=vx2;
vy2=vy2+ay2*dt;
x2(i+1)=x2(i)+vx2*dt+.5*ax2*dt^2;
y2(i+1)=y2(i)+vy2*dt+.5*ay2*dt^2;
t2(i+1)=t2(i)+dt;
i=i+1;
end
i=1
while min(y)> -.001
ax=-(D/m)*(vx*vx+vy*vy)^0.5*vx;
ay=-g-(D/m)*(vx*vx+vy*vy)^0.5*vy;
vx=vx+ax*dt;
vy=vy+ay*dt;
x(i+1)=x(i)+vx*dt+.5*ax*dt^2;
y(i+1)=y(i)+vy*dt+.5*ay*dt^2;
t(i+1)=t(i)+dt;
i=i+1;
end
plot(x,y,'-',x2,y2,'-')
legend('Drag', 'No Drag')
legend('show')
xlabel('x distance (m)')
ylabel('y distance (m)')
title('Projectile Path')
maybe try
Uwind = @(y) -75*(1-((75-y)/75)^2)
for some reason I'm not able to run your code , takes long time
It doesn't seem like its changing anything. When I add it into the vx components it doesn't alter the final plot
It doesn't seem like its changing anything. When I add it into the vx components it doesn't alter the final plot
can you show the code?
ax=-(D/m)*(vx*vx+vy*vy)^0.5*vx;
ay=-g-(D/m)*(vx*vx+vy*vy)^0.5*vy;
vx=Uwind+vx+ax*dt;
vy=vy+ay*dt;
x(i+1)=x(i)+vx*dt+.5*ax*dt^2;
y(i+1)=y(i)+vy*dt+.5*ay*dt^2;
t(i+1)=t(i)+dt;
i=i+1;

Sign in to comment.

Asked:

on 14 Oct 2018

Commented:

on 14 Oct 2018

Community Treasure Hunt

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

Start Hunting!