MATLAB: Any guidance how to solve this, really need this and will be grateful for any help.

MATLAB and Simulink Student Suitematlab function

clc
clear all
syms y
a = 0:0.5:10;
U = 1;
x= 0;
sym y
for m = 0:1:10
j = 1;
eqn = U*y -(m/(2*pi)*atan((2*a*y)/(x.^2 + y.^2 - a.^2)))== 0;
soly = solve(eqn,y);
Y(j,1) = double(soly);
j = j + 1;
end
I need to get values for y or solve the eqn for y

Best Answer

I cannot see any way to vectorise this, so slogging through it with nested loops seems to be the only option.
The Code
a = 0:0.5:10;
m = 0:1:10;
U = 1;
x = 0;
eqn = @(a,m,y) U*y -(m./(2*pi).*atan((2*a.*y)./(x.^2 + y.^2 - a.^2)));
for k1 = 1:length(a);
for k2 = 1:length(m)
for k3 = 1:2
y(k1,k2,k3) = fsolve(@(y)eqn(a(k1),m(k2),y), 100*(-1)^k3);
end
end
end
figure(1)
meshc(m, a, squeeze(y(:,:,1)))
hold on
meshc(m, a, squeeze(y(:,:,2)))
hold off
grid on
colormap(jet)
xlabel('m')
ylabel('a')
zlabel('y')
There are two roots to ‘y’ since it is quadratic in ‘y’. However, they are essentially indistinguishable, so appear as only one surface in the plot.