fsurf and function handles.

I rewrite my question in the hope of making it clearer.
Let H be a vertical half-plane in bounded by the vertical axis . In H, we use coordinates z, the height, and r, rhe distance from the vertical axis. So . A square card Cwith sidelength 2 lies flat on H, and is pinned through the centre of C to the point . C rotates freely about the pin, while remaining within H.
Now we start rotating Crotating about the pin through its centre at the rate of one revolution per minute, and then we start H rotating about the vertical axis at the rate of one revolution per minute.
The task is to draw the volume swept out by C. Here is my (failed) attempt.
R = 5;
A(:,1) = [1;1]; A(:,2) =[1;-1]; A(:,3)=[-1;1]; A(:,4) = [-1;-1];
A(:,5) = A(:,1);
syms rot(ang);
rot(ang) = [cos(ang),-sin(ang);sin(ang),cos(ang)];
syms edge(i,s);
edge(i,s) = [R;0] + s*A(:,i) + (1-s)*A(:,i+1);
figure; hold;
for i = 1:4
% use? second coordinate of the vector rot(ang)*edge(i,s) to specify funz
% use? first coord, say r, of the vector rot(ang)*edge(i,s) to specify
% funx as r*cos(ang) and funy as r*sin(ang)
fsurf(funx,funy,funz,[0,1,0,2*pi]);
end

3 comentarios

Walter Roberson
Walter Roberson el 10 de Dic. de 2018
Editada: Walter Roberson el 21 de Dic. de 2018
four fsurf calls with hold on set?
use a cell array of function handles if you need to.
David Epstein
David Epstein el 11 de Dic. de 2018
If it were possible to define a function inside a for loop (which I don't think is possible), then my problem would be solved.
If it were possible to define an anonymous function containing more than one executable statement my problem would be solved.
If I was prepared to write out the function definiitons of 12 different functions with 12 different names (which would require lots of repetitive code) my problem would be solved. There are 4 different strips, and fsurf requires three auxiiary functions, called funx, funy and funz in the documentation for fsurf. The code for each of the four strips would be almost identical.
Perhaps I need to learn how to use symbolic functions to do the job the "right" way.
Stephen23
Stephen23 el 21 de Dic. de 2018
Editada: Stephen23 el 22 de Dic. de 2018
"If it were possible to define a function inside a for loop (which I don't think is possible), then my problem would be solved."
It is possible by defining an anonymous function:
for k = ...
fun = @(...) ...;
...
end

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Etiquetas

Preguntada:

el 10 de Dic. de 2018

Editada:

el 22 de Dic. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by