CAT arguments dimensions are not consistent Error in Solving ode45 ?

I am getting the CAT argument dimensions error in computing two differential equations using ODE45. Apparently everything seems right and the vector I used seem to have same dimentions. The code is Give below.
% The memcapfinal.m includes the follwing code.
function qprime=memcapfinal(t,q);
e = 1.6*10^(-19); %C electron charge%
h = 6.63*10^(-34); %J/s planks constant%
phi = (0.3)*1.6*10^(-19); %J barrier height%
R=1;
Epsilon0 = 8.85*10^-12;
k1 = 100;
k2 = 10;
d=10*10^(-9);
s = 6*10^(-9);
m = 9.11*10^(-31); %kg electron mass%
A = 10^(-4);
b = -4*3.14*s/h;
c0=(A*Epsilon0*k1)/d;
t1=0:0.0000001:0.0005;
f=10000;
v0=7.5;
T=5/f;
v=v0*sin(2*3.14*f*t1);
plot(t1,v);
qprime=[((v/R)-(1/R)*(((d*q(1))+(s*q(2)))/(c0*d)));(sqrt(2*m*phi)/s*(e/h)^2*(((q(1)+q(2))/(2*A*Epsilon0*k2))*s)*exp(b*sqrt(2*m*phi)))*A];
And the code which calls the ODE is given below
clear all;
q0=[0 10^(-9)];
tspan1=[0,0.0005];
[t,q]=ode45(@memcapfinal,tspan1,q0)
subplot(2,1,1)
plot(t,q(:,1))
subplot(2,1,2)
plot(t,q(:,2))

 Risposta accettata

dbstop if caught error
then run the program. If it stops for any reason other than the cat problem, then use dbcont to keep going.
When it stops with the cat error, display
size( ((v/R)-(1/R)*(((d*q(1))+(s*q(2)))/(c0*d))) )
size( (sqrt(2*m*phi)/s*(e/h)^2*(((q(1)+q(2))/(2*A*Epsilon0*k2))*s)*exp(b*sqrt(2*m*phi)))*A )
As you do not appear to use t in your calculation, and as your code would error if q did not have at least 2 elements, I predict that the problem happens every time

10 Commenti

If you examine your code, you will see that t1 and v are long row vectors, but everything else is a scalar. The second component of your [;] expression involves only scalars so the result is going to be scalar. The first component involves a vector in the numerator and scalars otherwise, so the result is going to be a vector. You are then trying to use [;] between a row vector and a scalar. That is going to fail.
You are perhaps trying to create a column vector. If that is the case, then you need to switch v to column vector form. For example,
((v(:)/R)-(1/R)*(((d*q(1))+(s*q(2)))/(c0*d)))
Hi, Thanks for your response. using the column vector isn't essential . so i prefer to use row vector ,i.e v instead of v(:). and changed the plotting commands like this
subplot(2,1,1)
plot(t,q(1))
subplot(2,1,2)
plot(t,q(2))
But still getting the same CAT Dimention error. Then I changed the row vector into column vector as per your kind suggestion but still the same error popped out.
When I use v= some constant value, I works fine and gives me the results. But in my actual problem, v is a sinosidal waveform.
The plotting inside the function is not affected by whether you use a row or column vector. The row vs column vector is only to do with how you construct the two parts that you are concatenating together using [;] . If you switch your v to v(:) in your definition of qprime then that line will no longer fail, as it definitely would with your original code.
qprime=[((v(:)/R)-(1/R)*(((d*q(1))+(s*q(2)))/(c0*d)));(sqrt(2*m*phi)/s*(e/h)^2*(((q(1)+q(2))/(2*A*Epsilon0*k2))*s)*exp(b*sqrt(2*m*phi)))*A];
Your function would then return a column vector of length length(t1)+1, and length(t1) is 5001, so you are going to be outputting a column of length 5002. Note that it is mandatory that it be a column vector that is output by the function.
The column vector that is output for a particular time is turned into a row vector in the final output. The final solution matrix would have 5002 columns, and the number of rows the same as the length of the time vector.
Outside the ode45 call, the times being returned are not the same as the t1 inside your memcapfinal call. The times being returned are the times the ode45 call was called with respect to. For the sake of argument there might happen to be 37 of them, so your "q" matrix returned by ode45 would be 37 x 5002 . It doesn't make much sense to plot the first 5001 of them without knowing what t1 values they correspond to, so your meaningful plot becomes
plot(t, q(:,end))
as the last column does not correspond to any particular internal t1.
You might possibly be interested in looking at the output of
N = 10; first 10 t1's
plot(t, q(:,1:N).' )
this would produce N lines, following the first N values of t1 as they evolve across time. But without a legend() you would not know which line is which.
To go further than this you would need to consider 3D plots where the t1 values where one of the axes.
@Walter Roberson.....Thanks alot for such a great help. Can you kindly guide me how to use 3D plotting for this problem and How to get rid of this error of
""""EMCAPFINAL returns a vector of length 5002, but the length of initial conditions vector is 2. The vector returned by MEMCAPFINAL and the initial conditions vector must have the same number of elements.""""
Well, you have a problem then.
When you are using ode45, the initial conditions that you pass in, q0, become the left boundary conditions for the ODE. The value that you compute from your ode function is, I gather, considered to be the derivative at that point. And the initial conditions for the next call are determined by integrating all of the vector outputs you emitted before. So the length of the output vector needs to be the same as the length of the initial conditions because the integral of the output vector entries becomes the new initial conditions.
You probably intend your final entry in the column to act as the derivative for your second condition q(2). But it isn't clear which of your 5001 values to act as the derivative for your first condition.
I speculate that what should be happening is that you should be setting
t1 = t;
rather than your present
t1=0:0.0000001:0.0005;
with t1 being your current time, a scalar, the first value of the two you calculate would come out scalar, and the output would be a column vector of length 2, perfect for integrating to find the next conditions.
Don't forget to comment out the plot() inside the function.
@Walter Roberson...Thanks for your help. You are a life saver. I replaced t1=t and it worked perfectly.
Whew, you made me work for that one ;-) But now I understand ode better than I did before.
@Walter Roberson, In the same code I need to plot q(1) vs v and q(2) vs v. The problem is that v is always returned as undefined function . The length of t is 133 and that of q(1) and q(2) is 1.. The point is how to plot q(1) vs v and q(2) vs v ?
I am so sorry for bothering you again.I am so new to this kinda stuff.

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by