Clear Filters
Clear Filters

Error: Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters

3 views (last 30 days)
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])

Answers (1)

Walter Roberson
Walter Roberson on 2 May 2023
I had to guess about what you are trying to do.
n = 50;
x = -1 + 2.*rand (1,n)
x = 1×50
-0.5991 -0.5210 -0.7474 -0.9179 0.2134 0.7822 0.5500 -0.3415 0.1121 -0.2442 0.9066 0.9617 -0.0918 -0.8584 -0.8393 -0.8383 -0.3599 -0.0121 -0.0055 -0.0096 0.1896 0.8881 -0.6809 -0.4161 -0.1603 -0.6235 -0.2973 0.5422 0.5792 0.9235
y = -1 + 2.*rand (1,n)
y = 1×50
-0.1821 0.4905 0.6683 -0.8477 -0.1780 -0.9238 -0.8321 0.4223 -0.7923 -0.7137 0.5017 0.9251 -0.5448 0.2657 0.3568 -0.6313 -0.0869 -0.1506 -0.2911 -0.3678 -0.7103 0.6023 0.3364 -0.1782 -0.6253 -0.1144 0.0615 0.5388 0.8450 -0.3836
appr = (sum(x.*sin(1./x)<=1)/n)*4
appr = 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 Comments
Image Analyst
Image Analyst on 2 May 2023
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.

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!