MATLAB: Solving non linear equation with a range in MATLAB (problem)

non linear equation solving problem with range

I need to solve below non-linear equation with a range but cannot find a way to do it
Range of (x) is -40 to 30 with increments of 5. (x) is known but I need to find range of (y) and plot (x) vs (y). Please with the answer provide an explanation also. Thank you
p=0.5
S=(sin(y-x)-p*sin(x)*sin(y))=0

Best Answer

Hi Abdullah,
here is the code with comments:
x=[-40:5:30]'; % x in rad or °? Matlab uses rad
n = size(x,1); % numbers of calculations
yy=zeros(n,1); % preallocation of yy to make it a column-vector
for i=1:n
yy(i)=fsolve(@(y) fun(x(i),y),0); % solve implicit equation
end
figure
plot(x,yy) % plot it
function S=fun(x,y)
S=(sin(y-x)-0.5*sin(x)*sin(y)); % your function
end
Related Question