Array indices must be positive integers or logical values.

function [z]=phi(x)
%Determine phi(x) using the formulas provided
%2/25/21
%AE 227
a=0.4361836;
b=0.1201676;
c=0.937298;
r=exp(-.5*(x^2))/sqrt(2*pi);
t=1/(1+(0.3326*x));
z=0.5-r(a*t-b(t^2)+c(t^3));
end

 Accepted Answer

function [z]=phi(x)
%Determine phi(x) using the formulas provided
%2/25/21
%AE 227
a=0.4361836;
b=0.1201676;
c=0.937298;
r=exp(-.5*(x.^2))/sqrt(2*pi);
t=1./(1+(0.3326*x));
z=0.5-r.*(a*t-b*(t.^2)+c*(t.^3)); % <--- change in this line
end

5 Comments

why are you placing a . after r and t?
I was able to get it to work with
z=0.5-r*(a*t-b*(t^2)+c*(t^3));
why are you placing a . after r and t?
Read about element by element operations.
I was able to get it to work with z=0.5-r*(a*t-b*(t^2)+c*(t^3));
You cannot work with that, if x is a vector.
Would you be able to provide a link to element by element operations unable to find it in my book.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Asked:

on 26 Feb 2021

Commented:

on 26 Feb 2021

Community Treasure Hunt

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

Start Hunting!