Plot the shape of a squid based on mathematical equations
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Dyuman Joshi
2022-10-10
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 .*
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!