Create combined polar coordinates function
3 views (last 30 days)
Show older comments
Hello, I have been trying to solve for what angles my function r in polar coordinates cuts the unit circle and use the functions below to plot the solution. Now I am trying to come up with a function that given the input of a angle (x) gives the corresponding y value of the difference of the function and the unit circle so that I can calculate an exact solution with fzero. I am very confused on how to do this and been stuck on this for a while. Thanks in advance for any help.
%My function on a seperate script
function [x,y]=polarcoord(f)
theta=linspace(0,2*pi);
x=f(theta).*cos(theta);
y=f(theta).*sin(theta);
end
%Main script
r=@(x)(2+sin(3*x))./sqrt(1+exp(cos(x)));
[x,y]=polarcoord(r); %Main function
[X,Y]=polarcoord(@(x) 1); %Unit circle
0 Comments
Accepted Answer
Mathieu NOE
on 12 Dec 2022
hello
it seems to me there is a straightforward solution to your problem by using this Fex submission :
%Main script
r=@(x)(2+sin(3*x))./sqrt(1+exp(cos(x)));
[x,y]=polarcoord(r); %Main function
[X,Y]=polarcoord(@(x) 1); %Unit circle
P = InterX([x;y],[X;Y]);
plot(x,y,'-*',X,Y,'-*',P(1,:),P(2,:),'ro')
axis square
%My function on a seperate script
function [x,y]=polarcoord(f)
theta=linspace(0,2*pi,100);
x=f(theta).*cos(theta);
y=f(theta).*sin(theta);
end
NB the crossing points coordonates are interpolated so the angular resolution of your x,y, X,Y data is not (too) critical
zoomed plot :
2 Comments
Mathieu NOE
on 12 Dec 2022
Edited: Mathieu NOE
on 12 Dec 2022
This is another way to do it without the Fex InterX
simply look for the zero crossing values (theta) of your radius function minus the radius 1 circle.
this is ploted in figure 1
the cartesian plot is in fig 2
%Main script
theta=linspace(0,2*pi,100);
r=@(x)(2+sin(3*x))./sqrt(1+exp(cos(x)));
[x,y]=pol2cart(theta,r(theta)); %Main function
[X,Y]=pol2cart(theta,1); %Unit circle
thetac = zero_crossing(theta,r(theta)-1);
[xc,yc]=pol2cart(thetac,r(thetac)); % zero crossing points
figure(1),plot(theta,r(theta)-1,thetac,zeros(size(thetac)),'ro')
title('r(theta)-1')
xlabel('Theta (rad)');
ylabel('amplitude');
figure(2),plot(x,y,'-*',X,Y,'-*',xc,yc,'ro')
axis square
function xc = zero_crossing(x,y)
% zero crossing with linear interpolation
i = find(y(1:end-1).*y(2:end)<0); % index of zero crossings
m = (y(i+1)-y(i))./(x(i+1)-x(i)); % slope
xc =-y(i)./m+x(i); % x coordinates of zero crossings linear interpolated
end
More Answers (0)
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!