vpasolve returns empty sym 0-by-1

조회 수: 15 (최근 30일)
Alex Wylie
Alex Wylie 2017년 2월 6일
편집: Karan Gill 2017년 2월 13일
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
Alex Wylie
Alex Wylie 2017년 2월 6일
Yeah fair enough, sorry for being greedy. I appreciate everyone that spends any time trying to solve this problem. I have spent countless hours and any external insight is greatly appreciated. Sorry
Karan Gill
Karan Gill 2017년 2월 13일
편집: Karan Gill 2017년 2월 13일
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

댓글을 달려면 로그인하십시오.

답변 (1개)

John D'Errico
John D'Errico 2017년 2월 6일
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.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by