How to plot function within a set of axis?

I wrote a function code to calculate fStew. I have to plot the answer of the function within (pi,pi) but the graph is giving me blank? Here is what I wrote, fStew(theta)
ans =
-2.2737e-13
plot(fStew(theta))
I need it to be within (pi,pi) but my graph comes as blank.

2 Comments

Can you share your code?
function outerr = fStew(theta)
% a function to compute f(theta)
L1 = 2;
L2 = sqrt(2);
L3 = sqrt(2);
gam = pi/2;
p1 = sqrt(5);
p2 = sqrt(5);
p3 = sqrt(5);
x1 = 4;
x2 = 0;
y2 = 4;
%parameters are defined
A2 = L3*cos(theta) - x1;
B2 = L3*sin(theta);
A3 = L2*cos(theta + gam) - x2;
B3 = L2*sin(theta + gam) - y2;
%constants are defined
N1 = B3*(p2^2 - p1^2 - A2^2 - B2^2) - B2*(p3^2 - p1^2 - A3^2 - B3^2);
N2 = -A3*(p2^2 - p1^2 - A2^2 - B2^2) + A2*(p3^2 - p1^2 - A3^2 - B3^2);
D = 2*(A2*B3 - B2*A3);
%individual terms from equation 3
x = N1/D;
y = N2/D;
outerr = N1^2 + N2^2 - (p1*D)^2;
%residual from equation 4
end

Sign in to comment.

 Accepted Answer

It is because the output of the function is scalar. Try using a specified marker inside plot:
theta=pi/6;
plot(theta,fStew(theta),'o');set(gca,'XLim',[-pi pi])

3 Comments

Luna's answer moved here:
oh. So if I'm to plot the results of fStew(theta) within pi to pi I need it to be a matrix?
Not necessarily, but if you want to see a continuous line, then yes, you need to give theta input as a vector.
Also, change and save your function as follows( elementwise oepration edit is made in your function ):
function outerr = fStew(theta)
% a function to compute f(theta)
L1 = 2;
L2 = sqrt(2);
L3 = sqrt(2);
gam = pi/2;
p1 = sqrt(5);
p2 = sqrt(5);
p3 = sqrt(5);
x1 = 4;
x2 = 0;
y2 = 4;
%parameters are defined
A2 = L3*cos(theta) - x1;
B2 = L3*sin(theta);
A3 = L2*cos(theta + gam) - x2;
B3 = L2*sin(theta + gam) - y2;
%constants are defined
N1 = B3.*(p2.^2 - p1.^2 - A2.^2 - B2.^2) - B2.*(p3.^2 - p1.^2 - A3.^2 - B3.^2);
N2 = -A3.*(p2.^2 - p1.^2 - A2.^2 - B2.^2) + A2.*(p3.^2 - p1.^2 - A3.^2 - B3.^2);
D = 2.*(A2.*B3 - B2.*A3);
%individual terms from equation 3
x = N1./D;
y = N2./D;
outerr = N1.^2 + N2.^2 - (p1.*D).^2;
%residual from equation 4
end

Sign in to comment.

More Answers (0)

Asked:

on 2 Apr 2018

Edited:

on 2 Apr 2018

Community Treasure Hunt

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

Start Hunting!