Plot the shape of a squid based on mathematical equations
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ahmed Mohamed Mansoor
le 10 Oct 2022
Commenté : Dyuman Joshi
le 10 Oct 2022
The following equations plot a shape of a squid (as seen in the image below). I attempted to code the equations but I think there is something wrong in my code (see code below).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1151225/image.jpeg)
My code is:
clear; close all; clc;
[x,y] = meshgrid(linspace(-1,1,1000),linspace(-1,1,1000));
tot =0;
for i = 1:10
tot = tot + ((100/91) * (0.41 - (1/pi)*atan(25*x - 45)) .* ...
( 0.5 + (1/pi)*atan(25*(x + 0.3 + 0.45*((10*i-55)./45).^20))).* ...
exp(((x.^3./50 + x./4 + ((i-5)./60.*atan(8*x-384/29)) .* ...
(((-1).^(i+1)./20).*cos(5*x)-(i/60)) .*...
(0.475 - x./2 + (x-0.95).^2) .* (pi/2 - atan(40*x-38))-y).^2).*...
(-1500*pi + 3000.*atan(6 - 40.*(x-1.45).^2)) ));
end
f = -0.2 + tot.*(1 - 150*exp(-20*(500*(x-1).^2 + 500*(y-0.25).^2-1).^2));
f(f>0) = 1;
f(f<0) = 0;
contourf(x,y,f,[0 1])
axis equal
map = [1 1 1 ; 0 0 0];
colormap(map)
As you can see this is the plot I got.
Can you please check and let me know where I went wrong?
0 commentaires
Réponse acceptée
Dyuman Joshi
le 10 Oct 2022
There are some mistakes while defining tot.
3rd line inside atan it should be 384/25
and the immediate next symbol should be + (addition) instead of .*
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots 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!