Operator '*' is not supported for operands of type 'function_handle'
Show older comments
clear all;
clc;
r_value = 0:.01:.6;
r1 = r_value(:);
Z = [];
for i = 1 : length(r1)
r = r1(i);
i;
Z = [Z;fsolve(@(X)fun(X,r),1)];
end
function gss = fun(X,r)
S = X;
%%
gSq = 1.2;
%%
B = (100)^4;
Zp = 1.1;
Zn = 1.02;
Rp0 = 0.2/197.3;
Rn0 = 0.2/197.3;
%%
mS = 300;
mu = 2.16;
md = 4.67;
%%
pb = r*(197.3)^3;
t = 0;
pp = (1-(2*t))*pb/2;
pn = (1+(2*t))*pb/2;
%%
m1u = mu - gSq.*S;
m1d = md - gSq.*S;
%%
Rp = @(xup,xdp)fsolve(@(rp)f1(rp,xup,m1u,m1d,xdp,B,Zp),Rp0);
Rn = @(xun,xdn)fsolve(@(rn)f2(rn,xun,m1u,m1d,xdn,B,Zn),Rn0);
%%
Aup = @(xup)((sqrt(xup.^2 + (m1u*Rp)^2)) - (m1u*Rp)) ./ ((sqrt(xup.^2 + (m1u*Rp)^2)) + (m1u*Rp));
F1p = @(xup)((xup.*sin(xup)).^2 - Aup(xup).*((sin(xup)).^2 + (xup.*cos(xup)).^2 - (xup.*sin(2.*xup))));
xup = fsolve(@(xup,Rp) F1p(xup), 1);
%%
Aun = @(xun)((sqrt(xun.^2 + (m1u*Rn)^2)) - (m1u*Rn)) ./ ((sqrt(xun.^2 + (m1u*Rn)^2)) + (m1u*Rn));
F1n = @(xun)((xun.*sin(xun)).^2 - Aun(xun).*((sin(xun)).^2 + (xun.*cos(xun)).^2 - (xun.*sin(2.*xun))));
xun = fzero(@(xun) F1n(xun), 1);
%%
Adp = @(xdp)((sqrt(xdp.^2 + (m1d*Rp)^2)) - (m1d*Rp)) ./ ((sqrt(xdp.^2 + (m1d*Rp)^2)) + (m1d*Rp));
F2p = @(xdp)((xdp.*sin(xdp)).^2 - Adp(xdp).*((sin(xdp)).^2 + (xdp.*cos(xdp)).^2 - (xdp.*sin(2.*xdp))));
xdp = fzero(@(xdp) F2p(xdp), 1);
%%
Adn = @(xdn)((sqrt(xdn.^2 + (m1d*Rn)^2)) - (m1d*Rn)) ./ ((sqrt(xdn.^2 + (m1d*Rn)^2)) + (m1d*Rn));
F2n = @(xdn)((xdn.*sin(xdn)).^2 - Adn(xdn).*((sin(xdn)).^2 + (xdn.*cos(xdn)).^2 - (xdn.*sin(2.*xdn))));
xdn = fzero(@(xdn) F2n(xdn), 1);
%%
Oup = sqrt(xup^2 + (m1u*Rp)^2);
Oun = sqrt(xun^2 + (m1u*Rn)^2);
Odp = sqrt(xdp^2 + (m1d*Rp)^2);
Odn = sqrt(xdn^2 + (m1d*Rn)^2);
%%
M1p = (2*Oup + Odp - Zp)/Rp + 4*pi*Rp^3*B/3;
M1n = (2*Odn + Oun - Zn)/Rn + 4*pi*Rn^3*B/3;
%%
Sup = ((Oup/2) + (m1u*Rp*(Oup-1)))/((Oup*(Oup-1)) + (m1u*Rp/2));
Sun = ((Oun/2) + (m1u*Rn*(Oun-1)))/((Oun*(Oun-1)) + (m1u*Rn/2));
Sdp = ((Odp/2) + (m1d*Rp*(Odp-1)))/((Odp*(Odp-1)) + (m1d*Rp/2));
Sdn = ((Odn/2) + (m1d*Rn*(Odn-1)))/((Odn*(Odn-1)) + (m1d*Rn/2));
%%
DMpS = gSq*(2*Sup+Sdp);
DMnS = gSq*(Sun+2*Sdn);
%%
kp = (3*pp*pi^2)^(1/3);
kn = (3*pn*pi^2)^(1/3);
k1p = sqrt(kp^2 + M1p^2);
k1n = sqrt(kn^2 + M1n^2);
%%
Ip = M1p*((M1p^2*log(M1p^2))/4 - (M1p^2*log(kp + k1p))/2 + (kp*k1p)/2);
In = M1n*((M1n^2*log(M1n^2))/4 - (M1n^2*log(kn + k1n))/2 + (kn*k1n)/2);
F = ((1/pi^2) * (1/mS^2) * ((DMpS * Ip) + (DMnS * In))) - S;
gss = F ;
end
%%
function r = f1(rp,xup,m1u,m1d,xdp,B,Zp)
r = ((2*xup^2./sqrt(xup^2 + (m1u.*rp).^2)) + (xdp^2./sqrt(xdp^2 + (m1d.*rp).^2)) - Zp - (4*pi*B.*rp.^4));
end
function r = f2(rn,xun,m1u,m1d,xdn,B,Zn)
r = ((xun^2./sqrt(xun^2 + (m1u.*rn).^2)) + (2*xdn^2./sqrt(xdn^2 + (m1d.*rn).^2)) - Zn - (4*pi*B.*rn.^4));
end
In the above code i want to calculate S. within which we need to calculate xup,xdp,xun,xdn. where the Rp and Rn are again xup,xdp,xun,xdn dependent. I did it in this way but can not able to get result. Could you please help me out in this problem? I'm getting the problem like : "Operator '*' is not supported for operands of type 'function_handle'."
Accepted Answer
More Answers (0)
Categories
Find more on Random Number Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!