3

So I have to draw some graphs in MatLab.

At first I save this as a .m file:

function y = f(x)
y = sqrt((abs(sin(21*pi*x)))/(2+sin(20*pi*x)));

Then I do:

x=[0:0.05:1]
y=f(x)

and then when I need to draw the graph, using

plot(x,f) 

I get this error:

??? Input argument "x" is undefined.
Error in ==> f at 2
y = sqrt((abs(sin(21*pi*x)))/(2+sin(20*pi*x)));

Can someone tell me what is the problem here?

1 Answer 1

3

you need to have the ./ operator instead of / when dividing two vectors element by element. Try this instead

x = 0:0.05:1;
y = sqrt((abs(sin(21*pi*x)))./(2+sin(20*pi*x)));
plot(x,y)

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

hm.. i still get the error but it draws at least, a triangle :)
sorry, typo of 0.5 instead of 0.05 in the x step. I've edited the answer, try again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.