Error: Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters
2 次查看(过去 30 天)
显示 更早的评论
This is the code that I have so far. Up until t = linspace(0,2*pi); I do not get any errors. I'm unsure if i have to start a new thread for the second part of this question, but I'm also wondering how would one be able to write a generic code for this type of task.
x = -1 + 2.*rand (1,n)
y = -1 + 2.*rand (1,n)
appr = (sum(x.*sin(1./x)<=1)/n)*4
plot(x(x.*sin(1./x)<=1),y(x.*sin(1./x)<=1),".", ... "Color",[0.3 0.7 0.5], "MarkerSize",10)
hold on
plot(x(x.*sin(1./x0,y(x.*sin(1./x),".", ... "Color", [0.7 0.5 0.3], "MarkerSize",10)
t = linspace(0,2*pi);
plot(cos(t),sin(t),’LineWidth’,3,’Color’,[0.1 0.3 0.5])
0 个评论
回答(1 个)
Walter Roberson
2023-5-2
I had to guess about what you are trying to do.
n = 50;
x = -1 + 2.*rand (1,n)
y = -1 + 2.*rand (1,n)
appr = (sum(x.*sin(1./x)<=1)/n)*4
plot(x(x.*sin(1./x)<=1),y(x.*sin(1./x)<=1),".", ...
"Color",[0.3 0.7 0.5], "MarkerSize",10)
hold on
plot(x(x.*sin(1./x)>1),y(x.*sin(1./x)>1),".", ...
"Color", [0.7 0.5 0.3], "MarkerSize",10)
t = linspace(0,2*pi);
plot(cos(t),sin(t),"LineWidth",3,"Color",[0.1 0.3 0.5])
5 个评论
Image Analyst
2023-5-2
If this Answer solves your original question, then could you please click the "Accept this answer" link to award the answerer with "reputation points" for their efforts in helping you? They'd appreciate it. Thanks in advance. 🙂 Note: you can only accept one answer (so pick the best one) but you can click the "Vote" icon for as many Answers as you want. Voting for an answer will also award reputation points.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!