where to write function
이전 댓글 표시
m=0;
k0 = 1; la0 = 2*pi/k0; a = 0.3;
ec = 2.2^2; es = 1.7^2; ef = -4;
pc = ef/ec; ps = ef/es;
tol = 1e-12;
bsinf = sqrt(ef*es/(ef+es));
x = linspace(-3,3,601)*a;
plot(x/a, real(Hy), ’linewidth’,2);
function [be,E] = pwga(la0,ef,ec,es, a, bsinf, m, tol);
ga = sqrt(be^2-ef); as = sqrt(be^2-es); ac = sqrt(be^2-ec);
psi = atanh(-pc*ac/ga)/2- atanh(-ps*as/ga)/2
Hy = cosh(ga*a - psi).*exp(as*(x+a)).*(x<-a) + ...
cosh(ga*a + psi).*exp(-ac*(x-a)).*(x>a) + ...
cosh(ga*x + psi).*(abs(x)<=a);
end
pl plot the following
댓글 수: 8
Voss
2022년 2월 2일
You can save your function:
- In a function file which contains only function definitions. The name of the file must match the name of the first function in the file.
- In a script file which contains commands and function definitions. Functions must be at the end of the file. Script files cannot have the same name as a function in the file. Functions are supported in scripts in R2016b or later.
Files can include multiple local functions or nested functions. For readability, use the end keyword to indicate the end of each function in a file. The end keyword is required when:
- Any function in the file contains a nested function.
- The function is a local function within a function file, and any local function in the file uses the end keyword.
- The function is a local function within a script file.
shiv gaur
2022년 2월 2일
KSSV
2022년 2월 2일
@shiv gaur You have copied a function and it is not used in the code. To solve the plot problem, you need to define the variable Hy. What is it? How is it? From where you want to calculate?
Benjamin Thompson
2022년 2월 2일
What is your question? Please provide more details.
shiv gaur
2022년 2월 2일
Steven Lord
2022년 2월 2일
You've defined a function pwga but nowhere in your code do you call the pwga function. That function is where the only reference to be occurs, but pwga does not actually create a variable be. You will need to update the function so it actually creates a variable be then call that function.
shiv gaur
2022년 2월 2일
Steven Lord
2022년 2월 2일
Try updating the function yourself (it's a good way to learn.) If you are not able to successfully do so post your updated function and we can offer more feedback.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
