Too many Input arguments error
8 views (last 30 days)
Show older comments
I've written a basic script and am getting an error "SYM/VPA, Too many inputs arguments" in my line with s=vpa(y==terrain,x, '6');. I've read through other threads and am still missing what I've done wrong. The code is below. I appreciate any insight. Issue is specifically with line 16, for now....
clear
syms x
%Givens
v=300; %(m/s), Value based on user input
g=9.81; %m/s^2), Constant
h=4; %(m) starting launch height
theta=35; %(degrees), Value based on user input
q=0; %Zero value assigned for impact
%Calculations
y=h+x*tand(theta)-g*x^2/(2*v^2*cosd(theta)); %(Trajectory formula, angle input must be in degrees)
R=v^2*sin(2*theta)/g; %Range formula
terrain=.1*R; %Terrain slope formula based on given information. terrain slopes up by 1 m in y for every 10 m in x
s=vpa(y==terrain,x, '6');
fplot(R,[0,s], 'r')
hold on
fplot(y, [0,s], 'g')
%{
Apply interp1 command to return identified zero values of launch height
and impact location
%}
n=R;
zero_val_impact = zeros(2, 2);
zero_val_impact(1) = interp1(y(1:n/2), R(1:n/2), q, 'spline');
zero_val_impact(2) = interp1(y(n/2:end), R(n/2:end), q, 'spline');
%Creates scatter plot for the two zero value points on plot
scatter(zero_val_impact(:,1), zero_val_impact(:,2));
0 Comments
Answers (3)
VBBV
on 3 Nov 2022
clear
syms x
%Givens
v=300; %(m/s), Value based on user input
g=9.81; %m/s^2), Constant
h=4; %(m) starting launch height
theta=35; %(degrees), Value based on user input
q=0; %Zero value assigned for impact
%Calculations
y=h+x*tand(theta)-g*x.^2./(2*v^2*cosd(theta)); %(Trajectory formula, angle input must be in degrees)
R=v^2*sin(2*theta)/g %Range formula
terrain=.1*R %Terrain slope formula based on given information. terrain slopes up by 1 m in y for every 10 m in x
s = solve(y-terrain,x) % solve the equation for variable x
s=vpa(s,6) % 6 digits precision
X = double(subs(s,x,1:100)) % replace symbolic variable with a vector of values and convert to double array
plot(X(:,1),X(:,2)) % plot data
2 Comments
Walter Roberson
on 3 Nov 2022
You are obviously looking for a specific value in s, since you use it as a bound for fplot. I suspect that you are wanting to use vpasolve() passing in a starting guess of 6.
syms x
%Givens
v=300; %(m/s), Value based on user input
g=9.81; %m/s^2), Constant
h=4; %(m) starting launch height
theta=35; %(degrees), Value based on user input
q=0; %Zero value assigned for impact
%Calculations
y=h+x*tand(theta)-g*x^2/(2*v^2*cosd(theta)) %(Trajectory formula, angle input must be in degrees)
R = v^2*sin(2*theta)/g %Range formula
terrain=.1*R; %Terrain slope formula based on given information. terrain slopes up by 1 m in y for every 10 m in x
s = double(vpasolve(y==terrain,x, 6))
It is a polynomial, and for polynomials only vpasolve() returns all of the routes. So select the largest of them to plot against... and add a margin after that so that the bound is not right at the edge of the plot.
fplot(R,[0,max(s)+10], 'r')
hold on
fplot(y, [0,max(s)+10], 'g')
%{
Apply interp1 command to return identified zero values of launch height
and impact location
%}
n=R;
zero_val_impact = zeros(2, 2);
zero_val_impact(1) = interp1(y(1:n/2), R(1:n/2), q, 'spline');
zero_val_impact(2) = interp1(y(n/2:end), R(n/2:end), q, 'spline');
%Creates scatter plot for the two zero value points on plot
scatter(zero_val_impact(:,1), zero_val_impact(:,2));
y is a scalar symbolic expression: you cannot index it at 1:R/2 . You could potentially evaluate it at a list of points, if you used subs()
You use n=R then 1:n/2 as if R is a scalar. But right after that you use R(1:n/2) which implies that you think R is a vector -- but R is a numeric (not even symbolic) scalar. If you were to replicate the scalar R length(1:n/2) times then with all of those values being the same, interp1() is going to output the scalar for each location in range, so it is not even worth doing.
See Also
Categories
Find more on Spline Postprocessing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!