function myEquation (x)
a = 0.4361836;
b = 0.1201676;
c = 0.937298;
r = (e^(-0.5*(x^2)))/(2*pi)
t = 1/(1+(0.3326*x))
phi = 0.5 - r*((a*t)-(b*(t^2))+(c*(t^3)))
fprintf('The value of Φ(x) is: %i', phi)
fprintf('\n')
end
This is my current code. I am trying to use it to solve for the value of phi, and then print it. However, when I try to call it from the Command Window, it just says it is an unrecognized variable or function.

댓글 수: 1

Stephen23
Stephen23 2024년 2월 9일
"However, when I try to call it from the Command Window, it just says it is an unrecognized variable or function."
Most likely:
  • you have saved the function as a local function (i.e. after some other code in script or after another function),
  • you have saved the Mfile somewhere that is not on the MATLAB Search Path.

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

 채택된 답변

VBBV
VBBV 2024년 2월 9일

0 개 추천

myEquation(2)
r = 0.0215
t = 0.6005
phi = 0.4909
The value of Φ(x) is: 4.909191e-01
function myEquation (x)
a = 0.4361836;
b = 0.1201676;
c = 0.937298;
r = exp(-0.5*(x^2))/(2*pi)
t = 1/(1+(0.3326*x))
phi = 0.5 - r*((a*t)-(b*(t^2))+(c*(t^3)))
fprintf('The value of Φ(x) is: %i', phi)
fprintf('\n')
end

댓글 수: 3

r = exp(-0.5*(x^2))/(2*pi) % the variable e is not defined inside the function used to compute exponential
Replace undefined variable e with exp function
TheSaint
TheSaint 2024년 2월 9일
How would I call this from the command window?
Stephen23
Stephen23 2024년 2월 9일
편집: Stephen23 2024년 2월 9일
"How would I call this from the command window?"
Like this:
myEquation(2)
What is probably more important is where you have saved that function:
  • it must be the main function in an Mfile (i.e. it cannot be a local function or a nested function or part of a script),
  • the Mfile must be on the MATLAB Search Path (simplest is to save it in the current directory).

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Function Creation에 대해 자세히 알아보기

제품

릴리스

R2023b

질문:

2024년 2월 9일

댓글:

2024년 2월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by