assigning leads to empty value

I construct some functions depending on w. But if I assign some value w (of type double) with nonnegativ y df_v returns just a empty value [ ].
func = parabolicCylinderD(x(w),y));
df = diff(func)
....
f_v = func(w);
df_v = df(w);

댓글 수: 2

chicken vector
chicken vector 2023년 5월 15일
You need to share the code of your function otherwise it's impossible for us to help you.
The function is defined as follows
function [ Y1 ] = ypsilon1(a,z)
Y1 = exp(-0.25*z*z)*hypergeom(0.5*a+0.25,0.5,0.5*z*z);
end
function [ Y2 ] = ypsilon2(a,z)
Y2 = z*exp(-0.25*z*z)*hypergeom(0.5*a+0.75,1.5,0.5*z*z);
end
function [ U ] = Ufunction(a,z)
zeta = 0.5*a+0.25;
U = 1/(sqrt(pi)*2^(zeta))*(cos(pi*zeta)*gamma(0.5-zeta)*ypsilon1(a,z)-sqrt(2)*sin(pi*zeta)*gamma(1-zeta)*ypsilon2(a,z));
end
function [ D ] = parabolicCylinderD(v,z)
b = -v-0.5;
D = Ufunction(b,z);
end

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

답변 (2개)

chicken vector
chicken vector 2023년 5월 15일
편집: chicken vector 2023년 5월 15일

0 개 추천

The function fe containts a function called whittakerM which is not explicit and it can't be derived.
The problem originates from these two expression included in df:
diff(whittakerM(E.^2./2.0-M.^2./2.0+1.0./4.0,-1.0./4.0,k),E)
diff(whittakerM(E.^2./2.0-M.^2./2.0+1.0./4.0,1.0./4.0,k),E)
When you substitute values for E, M and k, the diff operation becomes numerical but is performed on only one double thus returning an empty value:
diff([1 2])
ans = 1
diff(1)
ans = []
In general you would have two options: either you derive a close form of whittakerM so you can perform analytical derivation, or you opt for numerical methods.
In your case you can't do neither of these because, as you can see from the expresions above, your variable E is also the degree of the derivative that has to be computed [diff(f,n) computes the n-th derivative].
This means that your function is defined for non-negative integers only and it is not continuous, thus the derivative has no mathematical meaning.

댓글 수: 7

Sef
Sef 2023년 5월 15일
But how do I than proceed. Because I have to solve fe with the Newton Raphson method. And for this I need the derivative and this is the reason why I compute dfe?
Now that you edited the question is even more clear that you can't use Newton-Raphson with analytical derivatives to solve this.
Your variable w is an index and is impossible to perform the derivative over an index.
If you riformulate your problem by eliminating w and using directly x as variable you can't still perform analytical derivatives for the same reason, but you can do it numerically.
In the following I used central derivatives, but you can use more accuate schemes or use matlab built-in method to solve your problem such as solve or fsolve.
f = @(x,y) parabolicCylinderD(x,y);
step = 5e-2;
X = 0:step:6;
dX = X(2:end) - step/2;
Y = 1:5;
M = length(Y);
N = length(X);
Z = zeros(M,N);
dZ = zeros(M,N-1);
for m = 1 : M
for n = 1 : N
Z(m,n) = f(X(n),Y(m));
end
dZ(m,:) = diff(Z(m,:)) / step;
end
figure;
tiledlayout(1,2);
nexttile;
plot(X,Z);
grid on;
title('Function');
legend(cellstr(compose('y = %d',1:M)),'Location','EastOutside');
nexttile;
plot(dX,dZ);
grid on;
title('Derivative');
function [ Y1 ] = ypsilon1(a,z)
Y1 = exp(-0.25*z*z)*hypergeom(0.5*a+0.25,0.5,0.5*z*z);
end
function [ Y2 ] = ypsilon2(a,z)
Y2 = z*exp(-0.25*z*z)*hypergeom(0.5*a+0.75,1.5,0.5*z*z);
end
function [ U ] = Ufunction(a,z)
zeta = 0.5*a+0.25;
U = 1/(sqrt(pi)*2^(zeta))*(cos(pi*zeta)*gamma(0.5-zeta)*ypsilon1(a,z)-sqrt(2)*sin(pi*zeta)*gamma(1-zeta)*ypsilon2(a,z));
end
function [ D ] = parabolicCylinderD(v,z)
b = -v-0.5;
D = Ufunction(b,z);
end
Sef
Sef 2023년 5월 24일
My overall aim was to so to say solve my equation withfunction f, also f(x(w),y)=0 and plot w vs y. Here f is parabolic cylinder function D_{x(w)}(y).
Thats why I introduced Newton-Raphson. Because I didnt know how to do in a other way.
@chicken vector thanks for your input. Maybe you can help me.
Sef
Sef 2023년 5월 30일
@chicken vector do you get what my problem is?
chicken vector
chicken vector 2023년 5월 30일
Attack what x and y are for you, because if x is a vector, you can just loop over each element of x and check if the result is zero.
If you don't share any data I still have the feeling your problem should be formulated differently and I can't help you more than this.
Sef
Sef 2023년 6월 5일
@chicken vector okay lets say (W-A)*parabolicCylinder(W^2-A,4*y) = f. And I would like to solve f=0 and plot than sotosay the results like W vs y
Sef
Sef 2023년 7월 6일
@chicken vector do you know what i mean. Do you have an idea to fix

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

Walter Roberson
Walter Roberson 2023년 5월 15일

0 개 추천

The basic problem is that there are two important functions named diff.
The primary diff() function calculates x(2:end) - x(1:end-1) which is numeric differences.
In the special case that the first parameter to diff() is symbolic or symfun then you instead get symbolic derivative (calculus).
Your code is working purely numerically, so diff() is numeric differences.
Note that numeric diff() does not do a numeric estimate of derivative: you need gradient() for that.

댓글 수: 1

Sef
Sef 2023년 5월 24일
alsowith gradient() there is the same error

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

카테고리

질문:

Sef
2023년 5월 15일

댓글:

Sef
2023년 7월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by