Hi there.I want to draw the following formula, but I get the following error
error: Vectors must be the same length.
why?
y(t) is a 41765*4 matrix and A=y(:,3).
for example y(:,3) having values as follows:
8.26665517322484e-08 - 3.08466436225798e-07i
2.94822110031966e-08 - 1.28642078260667e-07i
4.87811541654193e-08 + 1.34459400745398e-08i
5.20060276867161e-08 - 1.37015907821914e-07i
7.13757345297127e-08 - 2.06148057224859e-07i
8.21435079828878e-08 - 1.73652495134914e-07i
...
And my code in Matlab
tspan = [0 2e-9]; % time interval, up to 2 ns
y0 = [0+eps,0+eps,0+eps,0+eps];
[t,y] = ode45(@rate_eq_program_1,tspan,y0);
size(t);
t=t*1e9;
y = abs(y); % Change As Necessary To Get The Desired Resullt
delta_omega_laser=diff(atan(real(y(:,3))./imag(y(:,3))));
figure(1)
g = plot(t,delta_omega_laser ); % divided to normalize
xlabel('time [ns]','FontSize',14); % size of x label
ylabel('Arbitrary units','FontSize',14); % size of y label
set(gca,'FontSize',14); % size of tick marks on both axis
legend('\delta_omega', 'Location','SE') % legend inside the plot
Thanks in advance for helping!!

2 commentaires

diff is just difference between values:
dy(1) = y(2) - y(1);
dy(2) = y(3) - y(2);
%...
If you have 5 elements in y arrays. How many would you have in dy?
mohammad heydari
mohammad heydari le 8 Nov 2019
I mean derivation and implementation of formulas, not differences.y are calculated in ode and i want to calculate formulas.

Connectez-vous pour commenter.

 Réponse acceptée

M
M le 8 Nov 2019

0 votes

What lines causes the error ? Following one ?
g = plot(t,delta_omega_laser );
t and delta_omega_laser must have the same length.

14 commentaires

mohammad heydari
mohammad heydari le 8 Nov 2019
But both have the same length. I say this from workspace.
both have 41765.
darova
darova le 8 Nov 2019
  • But both have the same length
impossible. Please show
mohammad heydari
mohammad heydari le 8 Nov 2019
this is workspace and please pay attention to t and y----------y is a matrix with 41765*4
M
M le 8 Nov 2019
Modifié(e) : M le 8 Nov 2019
Yes, t and y have same dimensions, but you are trying to plot not t and y but t and delta_omega_laser.
Using the diff command, you lose one element in your vector.
mohammad heydari
mohammad heydari le 8 Nov 2019
Modifié(e) : mohammad heydari le 8 Nov 2019
Of course, delta_omega_laser. is a function of y .
What advice do you have for writing that formula? Is there another way?
You can shorten t vector
g = plot(t(2:end),delta_omega_laser);
mohammad heydari
mohammad heydari le 8 Nov 2019
There was an error resolving your suggestion but there is a problem.I should have the red curve in the figure below.s.png
But the shape I have is the following.The black and blue curves in the figure above are correctly obtained.
my.jpg
What is the problem?
image.png
You forgot to divide by dt
dA=diff(atan(real(y(:,3))./imag(y(:,3))));
delta = -dA./diff(t);
tnew = t(2:end) - diff(t)/2; % new vector "t" for delta
plot(tnew,delta)
Black points and curve is your original data y. Red points are positions where you calculate derivative
123.png
mohammad heydari
mohammad heydari le 9 Nov 2019
Modifié(e) : mohammad heydari le 9 Nov 2019
Thanks for your reply and I apologize for the delay in replying.
I got the following figure
This figure is much more promising than the previous one. But it's still not accurate.What other conditions do you recommend?
I just don't understand t (2: end) and tnew. What does this mean and why should it?
Best regards
darova
darova le 9 Nov 2019
  • I just don't understand t (2: end) and tnew. What does this mean and why should it?
Because the actual postion of a derivative between points:
So to draw correctly derivatives you have to correct you original t vector
How your graph looks like if you zoom in?
mohammad heydari
mohammad heydari le 9 Nov 2019
How your graph looks like if you zoom in?
As I put it above.Zooming in does not make a difference.
darova
darova le 9 Nov 2019
Impossible. Can you attach the data?
Try:
ylim([-1 1]*2e-7)
I don't know why you don't get the graph you want. I think the problem is deeper than it seems
Results make more sense if plot like this:
plot(real(y(:,3)),imag(y(:,3)),'.-b')
mohammad heydari
mohammad heydari le 9 Nov 2019
Modifié(e) : mohammad heydari le 9 Nov 2019
thanks alot for your help.
Trying to check again.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Performance 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!

Translated by