diff(abs(complex function)) stays complex -- wrong result
Show older comments
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 Comment
Answers (0)
Categories
Find more on Number Theory in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!