Too many Input arguments error

6 views (last 30 days)
peter jacobson
peter jacobson on 2 Nov 2022
Commented: peter jacobson on 4 Nov 2022
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');
Error using sym/vpa
Too many input arguments.
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));

Answers (3)

Maik
Maik on 3 Nov 2022
Edited: Maik on 3 Nov 2022
For the vpa function y==terrain is your x argument. No need to mention x in the input.
s=vpa(y==terrain,x, '6');
Instead use
s=vpa(y==terrain, '6');

VBBV
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
R = 7.0999e+03
terrain=.1*R %Terrain slope formula based on given information. terrain slopes up by 1 m in y for every 10 m in x
terrain = 709.9915
s = solve(y-terrain,x) % solve the equation for variable x
s = 
s=vpa(s,6) % 6 digits precision
s = 
X = double(subs(s,x,1:100)) % replace symbolic variable with a vector of values and convert to double array
X = 2×100
1.0e+03 * 1.1295 1.1295 1.1295 1.1295 1.1295 1.1295 1.1295 1.1295 1.1295 1.1295 1.1295 1.1295 1.1295 1.1295 1.1295 1.1295 1.1295 1.1295 1.1295 1.1295 1.1295 1.1295 1.1295 1.1295 1.1295 1.1295 1.1295 1.1295 1.1295 1.1295 9.3949 9.3949 9.3949 9.3949 9.3949 9.3949 9.3949 9.3949 9.3949 9.3949 9.3949 9.3949 9.3949 9.3949 9.3949 9.3949 9.3949 9.3949 9.3949 9.3949 9.3949 9.3949 9.3949 9.3949 9.3949 9.3949 9.3949 9.3949 9.3949 9.3949
plot(X(:,1),X(:,2)) % plot data
  2 Comments
VBBV
VBBV on 3 Nov 2022
solve the equation for variable x and plot
peter jacobson
peter jacobson on 4 Nov 2022
I appreciate the walkthrough and screenshots. Very helpful!

Sign in to comment.


Walter Roberson
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)
y = 
R = v^2*sin(2*theta)/g %Range formula
R = 7.0999e+03
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))
s = 2×1
1.0e+03 * 1.1295 9.3949
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');
Index exceeds the number of array elements. Index must not exceed 1.

Error in indexing (line 1079)
R_tilde = builtin('subsref',L_tilde,Idx);
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.
  1 Comment
peter jacobson
peter jacobson on 4 Nov 2022
Thank you for evaluating the initial probolem and highlighting my future issue. I figured the zero value lines were inoccrect but wanted to at least get my initial thoughts captured. I'll be incorperating your feedback into my script. Thank you again for the help!

Sign in to comment.

Categories

Find more on Contour Plots 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!