vpasolve returns empty sym 0-by-1
Show older comments
Hi,
I have written a function that has been working consistently. This is the function below, and I will describe its procedure and aim. The important section is for k(2) -> k(n). There is an equation w^2=-g*k*tan(kd) which has infinite solutions due to the periodicity of the tangens. I am trying to find each of these solutions. However today I changed a few values, namely d and n, and I have been getting the error: In an assignment A(:) = B, the number of elements in A and B must be the same (Error in k_construct (line 19) kx(h)=vpasolve(f2, k, kx(h-1));). I have worked out that the vpasolve(f2, k, kx(h-1)) is returning Empty sym: 0-by-1. I cannot understand why it is doing this as there must be solutions as a parabola must intersect the tangens. It is working for d = 0.07 but not d = 0.17 or d = 0.27. It is working for d = 0.5, d = 0.6 and so on. I can't seem to find any problem with my code, any help would be greatly appreciated. Thanks so much !!
function [kx] = k_construct(w, d, n, L)
%Function determines the k column vector with n solutions and then
%constructs a matrice with i and j values of k
%Constants
g=9.81; %m s^-2 (Gravitational Constant)
%First Term
syms k
f1=(w^2)-(g*k*tanh(k*d));
kx(1)=vpasolve(f1, k, [0 Inf]);
%Other solutions in column vector
f2=(w^2)+(g*abs(k)*tan(abs(k)*d));
h = 2;
while h <= n
vpasolve(f2, k, kx(h-1))
kx(h)=vpasolve(f2, k, kx(h-1));
q = 1;
while (((kx(h) - kx(h-1)) < (d*pi/(2*L))) | (kx(h) < 0))
kx(h) = vpasolve(f2, k, kx(h-1)+q);
q = q+1;
end
h = h + 1;
end
kx;
end
4 Comments
Alex Wylie
on 6 Feb 2017
John D'Errico
on 6 Feb 2017
http://www.mathworks.com/matlabcentral/answers/29922-why-your-question-is-not-urgent-or-an-emergency
Everyone wants an answer to their question immediately. YESSIR! We will get right to it.
Of course not all problems as posed have a solution.
Alex Wylie
on 6 Feb 2017
Karan Gill
on 13 Feb 2017
Edited: Karan Gill
on 13 Feb 2017
Did you try plotting the equation to ensure a solution does indeed exists? (i.e. the plot of "f2" crosses the zero line)
The vpasolve page has an example that shows the use of a plot to verify if a solution exists: https://www.mathworks.com/help/symbolic/vpasolve.html#bt51ety-1_1
Answers (1)
John D'Errico
on 6 Feb 2017
0 votes
Ok, I really think the answer is that not all problems have a solution.
I don't see a value for n or w or L, as I could then give you a better answer. A parabola need not intersect a line always.
So my suggestion is to plot the curve. There is only one unknown. So plot the function for the values of d where it fails. My guess is you will see no solution.
If you DO see a solution in the plot, then it should give you an idea of a starting value for vpasolve, telling it where to look. Or, if you can provide all of the constants, then I can take a better look at it. I'll check back in an hour.
Categories
Find more on Mathematics in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!