help finding vector slope
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
hello all,
I am trying to plot a vector named vec1, where
con = abs(g1-g2)/abs(t1:t2)*Fs));
vec1 = [g1*ones(1,Fs*t1),con*ones(1,Fs*t2), g2*ones(1,Fs*t3)];
What I want to see is a graph that has a linear slope from t1 to t2.
There must be something wrong with the con variable, but I can't get my head around it. Any help?
Thank you in advance
Réponse acceptée
Youssef Khmou
le 12 Fév 2013
Try this :
Fs=1000;
T=(0:1/Fs:20-1/Fs);
V=zeros(1,length(T));
t1=3;
t2=5;
g1=7;
g2=4;
for t=1:length(T)
if T(t)<=t1
V(t)=g1;
elseif T(t)>t1 && T(t) <=t2
V(t)=-(g1-g2)/(t2-t1)*T(t)+1.65*g1;
elseif T(t)>t2
V(t)=g2;
end
end
figure,
plot(T,V)
axis([0 20 0 10]), xlabel('time in Seconds');
ylabel(' Magnitude dB');title(' Gain')
2 commentaires
Youssef Khmou
le 12 Fév 2013
Modifié(e) : Youssef Khmou
le 12 Fév 2013
Tony, yes i forgot to mention that :
So your function in the 2dn region is defined as : y =ax+ b with negative slope :
vect(t) = a*T(t) + constant .
The slope is a= g1-g2/(t2-t1)= -3/2 .
to derive the constant : you take the initial condition :
At t=t1 vect(t1)=g1=a*t1+constant => constant=g1-a*t1=11.5 .
you can put 11.55 instead of g1*1.65 ,the reason i did g1*1.65 is because i derived the solution before you gave the details g1,t1,.. it was an approximation rather than solution from ax+b.
Plus de réponses (4)
the cyclist
le 12 Fév 2013
You don't really give enough detail to diagnose this, but I did notice that in the line
con = abs(g1-g2)/abs(t1:t2)*Fs));
the parentheses are balanced, so it's not a valid MATLAB statement.
0 commentaires
Youssef Khmou
le 12 Fév 2013
hi, you have to declare all variables in your example like others said so as to examine the code , but now details are missing .
0 commentaires
Voir également
Catégories
En savoir plus sur Numerical Integration and Differentiation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!