plotting a derivative of a function using surf command
조회 수: 1 (최근 30일)
이전 댓글 표시
I am trying to plot a derivative of a function using surf command, but when I evaluate it an error occur "Data dimensions must agree".
This is what I typed:
close all;
X=-10:.1:10;
T=-10:.1:10;
mu1=-.01+1*1i;
a=(.1-2*1i);
b=(.1-.1*1i);
[x,t]=meshgrid(X,T);
x1=exp(-1i*mu1.*x).*exp((1-(1i./(2*mu1)).*t));
x2=exp(1i*mu1.*x).*exp((1+(1i./(2*mu1)).*t));
y1=exp(-1i*mu1.*x).*exp((1+(1i./(2*mu1)).*t));
y2=exp(1i*mu1.*x).*exp((1-(1i./(2*mu1)).*t));
A=2*1i*(1)*a*conj(b)*x1.*conj(x2).*(x2.*conj(y1)-y2.*conj(x1));
B=(a.*conj(a).*x1.*conj(x1).*y2.*conj(y2)+b.*conj(b).*x1.*conj(y1).*x2.*conj(y2)+a.*conj(a).*x2.*conj(x2).*y1.*conj(y1)+b.*conj(b).*y1.*conj(x2).*y2.*conj(x1));
r1=-2.*1i.*((A./B));
dr1=diff(r1);
dt=diff(t);
dr1dt=dr1./dt;
td=t(2:end);
surf(x,td,abs(dr1dt));
댓글 수: 1
KSSV
2019년 3월 8일
X=-10:.1:10;
T=-10:.1:10;
mu1=-.01+1*1i;
a=(.1-2*1i);
b=(.1-.1*1i);
[x,t]=meshgrid(X,T);
x1=exp(-1i*mu1.*x).*exp((1-(1i./(2*mu1)).*t));
x2=exp(1i*mu1.*x).*exp((1+(1i./(2*mu1)).*t));
y1=exp(-1i*mu1.*x).*exp((1+(1i./(2*mu1)).*t));
y2=exp(1i*mu1.*x).*exp((1-(1i./(2*mu1)).*t));
A=2*1i*(1)*a*conj(b)*x1.*conj(x2).*(x2.*conj(y1)-y2.*conj(x1));
B=(a.*conj(a).*x1.*conj(x1).*y2.*conj(y2)+b.*conj(b).*x1.*conj(y1).*x2.*conj(y2)+a.*conj(a).*x2.*conj(x2).*y1.*conj(y1)+b.*conj(b).*y1.*conj(x2).*y2.*conj(x1));
r1=-2.*1i.*((A./B));
dr1=gradient(r1);
dt=gradient(t);
dr1dt=dr1./dt;
td=t(2:end);
surf(x,t,abs(dr1dt)');
But you need re think on your code.
답변 (1개)
KSSV
2019년 3월 8일
X=-10:.1:10;
T=-10:.1:10;
mu1=-.01+1*1i;
a=(.1-2*1i);
b=(.1-.1*1i);
[x,t]=meshgrid(X,T);
x1=exp(-1i*mu1.*x).*exp((1-(1i./(2*mu1)).*t));
x2=exp(1i*mu1.*x).*exp((1+(1i./(2*mu1)).*t));
y1=exp(-1i*mu1.*x).*exp((1+(1i./(2*mu1)).*t));
y2=exp(1i*mu1.*x).*exp((1-(1i./(2*mu1)).*t));
A=2*1i*(1)*a*conj(b)*x1.*conj(x2).*(x2.*conj(y1)-y2.*conj(x1));
B=(a.*conj(a).*x1.*conj(x1).*y2.*conj(y2)+b.*conj(b).*x1.*conj(y1).*x2.*conj(y2)+a.*conj(a).*x2.*conj(x2).*y1.*conj(y1)+b.*conj(b).*y1.*conj(x2).*y2.*conj(x1));
r1=-2.*1i.*((A./B));
dr1=gradient(r1);
dt=gradient(t);
dr1dt=dr1./min(diff(T));
td=t(2:end);
surf(x,t,abs(dr1dt)');
To get dt you can use difference in T. You need not to take a matrix. ANote that dt is same i.e 0.01. If you use a matrix..it is coming out to be zero matrix and makes dr1dt a nan or inf matrix. I advice you to still rethink on your code.
댓글 수: 5
KSSV
2019년 3월 8일
diff reduces the dimension by one....ad you are subtracting the consecutive elements. Gradient will not reduce the dimensions.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!