the error of not enough input arguments
Afficher commentaires plus anciens
Hello,
i am trying to run the below code , but it gives me the error of not enough input arguments
can anyone help me
thanks in advance
the code is:
d1= 1545e-9:1e-9:1548e-9;
d2= 1548e-9:0.1e-9:1557e-9;
d3= 1557e-9:1e-9:1575e-9;
d=[d1 d2 d3];
o=b(2,:);
% the begin of apodized DFB
is=length(d);
l=40e-3;
no=1e-5;
pi=22/7;
a=4*log(2);
e=l/ii;
for i1=1:is
i1
x(i1)=9.19.*( (1/d(i1))-(1e9/1550));
k(i1)=@(z) (pi/d(i1)).*no.*exp(-a.*((z-(l/2))/l).^2);
kt=(pi/1550e-9)*no;
g= 0.98*(4*kt*exp(-kt*l)+0.15);
q(i1)=sqrt(((g-(1j*x(i1)).^(2))+(k(i1).^2)));
dfdz(i1)=@(z,f) [ (1j.*k(i1)).*(f(2))-((g-(1j.*x(i1))).*f(1)); ( -1j.*k(i1).*(f(1)))+((g-(1j.*x(i1))).*f(2)) ];
bc2(i1)=@(fa,fb)[ fa(1)-o(i1); fb(2) ];
finit(i1)=@(z)[((-1j./k(i1)).*((q(i1).*(((k(i1).*o(i1))./(x(i1).*tanh(l.*q(i1)) + (g.*tanh(l.*q(i1)).*1j) - q(i1).*1j).*cosh((q(i1).*z))+(-(k(i1).*o(i1).*tanh(l.*q(i1)))./(x(i1).*tanh(l.*q(i1)) + g.*tanh(l*q(i1))*1j - q(i1).*1j).*sinh((q(i1).*z)))))+((g-(1j.*x(i1))).*((-(k(i1).*o(i1).*tanh(l.*q(i1)))./(x(i1).*tanh(l.*q(i1)) + g.*tanh(l.*q(i1)).*1j - (q(i1).*1j)).*cosh(q(i1).*z)+((k(i1).*o(i1))./(x(i1).*tanh(l.*q(i1)) + g.*tanh(l.*q(i1)).*1j - q(i1).*1j).*sinh(q(i1).*z))))))));(-(k(i1).*o(i1).*tanh(l.*q(i1)))./(x(i1).*tanh(l.*q(i1)) + g.*tanh(l.*q(i1))*1j - q(i1).*1j).*cosh(q(i1).*z))+((k(i1).*o(i1))./(x(i1).*tanh(l.*q(i1)) + (g.*tanh(l.*q(i1)).*1j) - (q(i1).*1j)).*sinh(q(i1).*z))];
dbstop if error
solinit2(i1)=bvpinit(linspace(0,l),finit(i1));
sol2(i1)=bvp4c(dfdz(i1),bc2(i1),solinit2(i1));
idx2= e:e:l;
u(:,i1)=deval(sol2(i1),idx2(i1));
delta2(i1)=l.*x(i1);
diff2(i1)=d(i1)-(1550e-9);
end
8 commentaires
Alex Mcaulley
le 7 Juin 2019
Can you put the complete red errot text?
Walter Roberson
le 7 Juin 2019
k(i1)=@(z) (pi/d(i1)).*no.*exp(-a.*((z-(l/2))/l).^2);
That line creates a function handle and attempts to store it at k(i1) . That will work when i1 is 1, so you are writing to k(1), but it will fail if i1 is anything else. It is not permited to create regular arrays of function handles, only cell arrays of function handles, k{i1} = ...
Jan
le 7 Juin 2019
Walter hits the point. The same for dfdz, bc2, finit
Hint: Avoid "l" (lower case L) as name of a variable. It is confused with 1 (one) too often.
dbstop if error will increase the run time. Use this for debugging only and do not insert it in productive code.
ayman elashmawy
le 7 Juin 2019
Modifié(e) : per isakson
le 7 Juin 2019
I cannot run your code due to the missing input data, e.g. b.
q1 and solinit2 still use round parentheses instead or curly braces.
The error message ist clear: The Jacobian is singular. This might be caused by a moistake in the formula, but of course the forum cannot fix this for you.
Avoid to insert too many parentheses, except if they calrify the mathematical meaning. In opposite to the clutter caused by unneeded parentheses, spaces would increase the readability massively. The elementwise multiplication .* is needed for arrays only. In your code it is applied exhaustively without a need, as far as I can see. This is not an error, but harder to read.
o = b(2, :);
is = length(d);
L2 = 40e-3;
no = 1e-5;
pi = 22 / 7; % A bad idea to redefing pi !!! Don't do this
a = 4 * log(2);
e = L2 / ii;
kt = pi / 1550e-9 * no;
for i1 = 1:is
x(i1) = 9.19 * (1 / d(i1) - 1e9 / 1550);
k(i1) = @(z) pi / d(i1) * no * exp(-a * ((z - L2 / 2) / L2) ^ 2);
g = 0.98 * (4 * kt * exp(-kt * L2) + 0.15);
q(i1) = @(z) sqrt(g - (1j .* x(i1)) ^ 2 + k(i1) ^ 2);
dfdz{i1} = @(z, f) [ 1j * k(i1) * f(2) - (g - 1j * x(i1)) * f(1); ...
-1j * k(i1) * f(1) + (g - 1j * x(i1)) * f(2)];
bc2{i1} = @(fa, fb) [fa(1) - o(i1); fb(2)];
finit{i1} = @(z) [(-1j / k(i1) * ((q(i1) * ...
((k(i1) * o(i1) / (x(i1) * tanh(L2 * q(i1)) + ...
... I gave up here
g.*tanh(L2.*q(i1)).*1j - ...
q(i1).*1j).*cosh((q(i1).*z)) + ...
(-(k(i1).*o(i1).*tanh(L2.*q(i1)))./(x(i1).*tanh(L2.*q(i1)) + ...
g.*tanh(L2*q(i1))*1j - ...
q(i1).*1j).*sinh((q(i1).*z)))))+ ...
((g-(1j.*x(i1))).*((-(k(i1).*o(i1).*tanh(L2.*q(i1))) ./ ...
(x(i1).*tanh(L2.*q(i1)) + g.*tanh(L2.*q(i1)).*1j - ...
(q(i1).*1j)).*cosh(q(i1).*z)+ ...
((k(i1).*o(i1))./(x(i1).*tanh(L2.*q(i1)) + ...
g.*tanh(L2.*q(i1)).*1j - ...
q(i1).*1j).*sinh(q(i1).*z)))))))); ...
(-(k(i1).*o(i1).*tanh(L2.*q(i1)))./(x(i1).*tanh(L2.*q(i1)) + ...
g.*tanh(L2.*q(i1))*1j - ...
q(i1).*1j).*cosh(q(i1).*z)) + ...
((k(i1).*o(i1))./(x(i1).*tanh(L2.*q(i1)) + ...
(g.*tanh(L2.*q(i1)).*1j) - (q(i1).*1j)).*sinh(q(i1).*z))];
solinit2(i1) = @(z) bvpinit(linspace(0,L2), finit{i1});
sol2(i1) = bvp4c(dfdz{i1}, bc2{i1}, solinit2(i1));
idx2 = e:e:L2;
u(:,i1) = deval(sol2(i1), idx2(i1));
delta2(i1) = L2 .* x(i1);
diff2(i1) = d(i1) - 1550e-9;
end
ayman elashmawy
le 8 Juin 2019
Walter Roberson
le 9 Juin 2019
If we had data to go on...
John D'Errico
le 9 Juin 2019
Modifié(e) : John D'Errico
le 9 Juin 2019
We cannot know what problem you arre running into. That is because we have no data to go on, to test your code out.
And Jan is totally correct. Redefining pi to be 22/7 is a terrible idea. pi already exists in MATLAB. There is no need to define it as an incorrect value!!!!!!! All that does is start you out in trouble.
So even though you think the problem is the initial guess, that is not terribly relevant, since we lack any data tto use. How can we possibly know what a good initial guess would be for some totally complicated, problem, one where we see no data to base anything on?
Oh - there is no need to put the line:
dbstop if error
in the middle of your code. That will only slow it down. You can set dbstop ONCE if you want it turned on, before you ever run the code. That is entirely sufficient. But if your code is not generating errors, then it won't generate errors, and therefore, having dbstop turned on at all will only slow your code down.
Another obvious error:
e=l/ii;
You use the variable ii but it is never defined.
Réponses (0)
Catégories
En savoir plus sur Multirate Signal Processing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!