diff(abs(complex function)) stays complex -- wrong result

Hi, i'm a newbe. Wanted to diff the abs of a complex function, but got wrong results. The problem seems to be that diff(abs ...) stays complex and then there somthing gets weird. Thx for the help.
clear
format compact
syms x real;
v(x)=1j*x/(1j*2*x+1.1)^2;
re(x) = real(v(x));
im(x) = imag(v(x));
vabs(x) = sqrt(re(x)^2+im(x)^2);
vabsdiff(x) = diff(vabs(x))
x0a= solve(vabsdiff(x)==0,x); %correct
fprintf('abs of complex function correct => correct\n') ;
av(x)=abs(v(x));
fprintf('diff abs => correct\n') ;
diffav(x)=diff(abs(v(x)));
assume(x>0);
x0b= solve(diffav(x)==0,x); %wrong
n=1001;
t=linspace(000.1,10,n);
%numeric now
%attention: diff just calculates the delta y; delta x = 1 ==> correction
%of delta x
diffnumeric=diff(double(vabs(t)))/((t(end)-t(1))/n);
subplot(2,2,1);
plot(t,double(av(t)));
title('The original function');
subplot(2,2,2);
plot(t(1:end-1),double(diffnumeric));
title('Diff numeric');
subplot(2,2,3);
plot(t,vabsdiff(t)); %should look like subplot 2
title('Diff symbolic via sqrt(re^2+im^2');
subplot(2,2,4);
plot(t,diffav(t),'r'); %should look like subplot 2
% warning => treated as complex
title('Diff symbolic via diff(abs)) W R O N G !');

댓글 수: 1

Adam
Adam 2014년 12월 11일
편집: Adam 2014년 12월 11일
Please remember to include relevant product information in the 'Products' list.
'syms' requires the Symbolic Toolbox and looks as though it does not behave the same as normal data.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

질문:

2014년 12월 11일

편집:

2014년 12월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by