help plot of function using handle

2 views (last 30 days)
b1 =1
b2 =2
b3 =3
%--------Function:
G =@(k) -2*k.^2 + b1 + sqrt( (-4*k.^4 - b2*k.^2 + sqrt((-4*k.^4 - b3*k.^2).^2 + b4^2 ))/2)
%-------Grid:
k = [-2:0.01:2]
% y = bsxfun(f,x,p)
% %-------Plot
%
% figure
plot(k,G)
help code wont run

Accepted Answer

Star Strider
Star Strider on 5 May 2022
Call ‘G’ with its argument —
b1 =1
b1 = 1
b2 =2
b2 = 2
b3 =3
b3 = 3
b4 = 4 % Replace Missing Value
b4 = 4
%--------Function:
G =@(k) -2*k.^2 + b1 + sqrt( (-4*k.^4 - b2*k.^2 + sqrt((-4*k.^4 - b3*k.^2).^2 + b4^2 ))/2)
G = function_handle with value:
@(k)-2*k.^2+b1+sqrt((-4*k.^4-b2*k.^2+sqrt((-4*k.^4-b3*k.^2).^2+b4^2))/2)
%-------Grid:
k = [-2:0.01:2]
k = 1×401
-2.0000 -1.9900 -1.9800 -1.9700 -1.9600 -1.9500 -1.9400 -1.9300 -1.9200 -1.9100 -1.9000 -1.8900 -1.8800 -1.8700 -1.8600 -1.8500 -1.8400 -1.8300 -1.8200 -1.8100 -1.8000 -1.7900 -1.7800 -1.7700 -1.7600 -1.7500 -1.7400 -1.7300 -1.7200 -1.7100
% y = bsxfun(f,x,p)
% %-------Plot
%
% figure
plot(k,G(k))
.

More Answers (1)

Benjamin Kraus
Benjamin Kraus on 5 May 2022
An alternative approach: Use fplot.
b1 = 1;
b2 = 2;
b3 = 3;
b4 = 4;
G =@(k) -2*k.^2 + b1 + sqrt( (-4*k.^4 - b2*k.^2 + sqrt((-4*k.^4 - b3*k.^2).^2 + b4^2 ))/2);
fplot(G)
xlim([-2 2])

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by