please can anyone know how to run this code
syms w12 b12 w34 b34 a1 y0
z2 = w12*a1 + b12;
a2 = elu(z2);
z4 = w34*a2 + b34;
a4 = elu(z4);
MSE=1/2*(a4-y0).^2;
ew12=diff(MSE,w12);
eb12=diff(MSE,b12);
ew34=diff(MSE,w34);
eb34=diff(MSE,b34);
and the elu is a function which is
function fr = elu(x)
f = zeros(length(x),1);
for i = 1:length(x)
if x(i)>=0
f(i) = x(i);
else
f(i) = 0.2*(exp(x(i))-1);
end
end
fr = f;
end
any suggestions?

 Akzeptierte Antwort

Utkarsh Belwal
Utkarsh Belwal am 9 Okt. 2020

0 Stimmen

Hello Ali,
I can see that you have declared symbolic variables and then you are passing these variables to the ‘elu’ function. In the function you are comparing a symbolic variable with a numerical value which is not possible and that’s why you are getting an error.
To do a comparison you have to substitute the symbolic variable with a value and for that you can use the Symbolic Substitution in MATLAB. Please refer to the documentation for more information.

3 Kommentare

Ali Najem
Ali Najem am 9 Okt. 2020
thanks Utkarsh for your reply
yes, thats correct but as you can see in code i cannot use diff becouse elu and inside elu there is two values
i need to obtaine all these equation as a syms
ew12=diff(MSE,w12);
eb12=diff(MSE,b12);
ew34=diff(MSE,w34);
eb34=diff(MSE,b34);
and then pass values to all of them to get answers
note: all these w12 b12 w34 b34 a1 y0 syms are matrix
a1=randn(784,1)*sqrt(2/784);
w12 = randn(300,784)*sqrt(2/784);
b12 = randn(300,1);
w34 = randn(10,300)*sqrt(2/300);
b34 = randn(10,1);
y0=randn(10,1)*sqrt(2/784);
is that possible to get answe i tried many times i stuck with elu function
thanks alot
I can see that 'elu' function doesn't need symbolic variables so you can do a type conversion before passing it to the 'elu' function as follows:
a2 = elu(double(subs(z2)));
z4 = w34*a2 + b34;
a4 = elu(double(subs(z4)));
Ali Najem
Ali Najem am 10 Okt. 2020
thank you so much sir i will try it

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by