Plotting a function with different range of values for arguments
2 ビュー (過去 30 日間)
古いコメントを表示
I am trying to plot a function with two different inputs, so its two plots in one graph actually. There are some constants which I have predefined. The function I want to plot is
$f(k,|T|^2)(=|T|^2/|R|^2)=|(e^{ik}-e^{-ik})/(1+(\delta-e^{ik})(e^{ik}-\nu)|^2$
The plots to be produced are for k=pi/2 and k=-pi/2, so I predefined these things in the code. However, when I try to plot the function for T, I get error saying that Undefined function or variable 'T'. The code I wrote is:
clear all
v0=-2.5;
epsilon=0.05;
v1 = v0*(1+epsilon);
v2 = v0*(1-epsilon);
g = 1;
k=pi/2
l=-k
w=-2*cos(k)
w1=-2*cos(l)
nu=v2-w+g.*T.^2;
delta=v1-w+g.*T.^2.*(1-2.*nu*cos(k)+nu.^2);
nu1=v1-w1+g.*T.^2;
delta1=v2-w1+g.*T.^2.*(1-2.*nu*cos(k)+nu.^2);
fplot(@(T) abs((exp(i*k)-exp(-i*k))/(1+(nu-exp(i*k)).*(exp(i*k)-delta)))^2,[0,5],'b')
hold on
fplot(@(T) abs((exp(i*l)-exp(-i*l))/(1+(nu1-exp(i*l)).*(exp(i*l)-delta1)))^2,[0,5],'b')
hold off
So whats going wrong here? Secondly, is it the correct way for plotting functions which have an injected argument?
UPDATE
Ok this has been fixed by an ugly way with the following code: (Is there a better neater way to to do it?)
clear all
v0=-2.5;
epsilon=0.05;
v1 = v0*(1+epsilon);
v2 = v0*(1-epsilon);
g = 1;
T=[0:0.01:5];
k=pi/2
l=-k
w=-2*cos(k)
w1=-2*cos(l)
nu=v2-w+g.*T.^2;
delta=v1-w+g.*T.^2.*(1-2.*nu*cos(k)+nu.^2);
nu1=v1-w1+g.*T.^2;
delta1=v2-w1+g.*T.^2.*(1-2.*nu*cos(k)+nu.^2);
ftn1=abs((exp(i*k)-exp(-i*k))./(1+(nu-exp(i*k)).*(exp(i*k)-delta))).^2;
ftn2=abs((exp(i*l)-exp(-i*l))./(1+(nu1-exp(i*l)).*(exp(i*l)-delta1))).^2;
plot(T,ftn1,T,ftn2)
0 件のコメント
採用された回答
Walter Roberson
2018 年 11 月 5 日
nu = @(T) v2-w+g.*T.^2;
delta = @(T) v1-w+g.*T.^2.*(1-2.*nu(T)*cos(k)+nu(T).^2);
nu1 = @(T) v1-w1+g.*T.^2;
delta1 = @(T) v2-w1+g.*T.^2.*(1-2.*nu(T)*cos(k)+nu(T).^2);
fplot(@(T) abs((exp(i*k)-exp(-i*k))/(1+(nu(T)-exp(i*k)).*(exp(i*k)-delta(T))))^2,[0,5],'b')
hold on
fplot(@(T) abs((exp(i*l)-exp(-i*l))/(1+(nu1(T)-exp(i*l)).*(exp(i*l)-delta1(T))))^2,[0,5],'b')
hold off
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!