Error: Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Walter Roberson
le 2 Mai 2023
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 commentaires
Image Analyst
le 2 Mai 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.
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!