From: Mohammad on
Hi guys.

I currently have a plotting function, trail5(m,n,o) where I want to make sure that at any time m+n+o=integer. I also want to make trail5(m,n,o)=plot with values of 1 through d in stems of 1/2, 1 through g in stems of 1/2, 1 through h in stems of 1/2, in order to make many copies of my image. (I input d,g,h as a boundary)

For the m+n+o=integer part, I've tried to build off a suggestion of a nested for loop:

for m=1:.5:d
for n=1:.5:g
for o=1:.5:h
V = n+m+o;
if V~=floor(V)
trail5(m,n,o) %what I want to solve for in every possible value of m,n,o
end
end
end
end

Is there a simple way to fix this so that trail5(m,n,o) works, and so that m+n+o=integer?

Thanks!

Cordially, Mohammad
From: Matt Fig on
Did you read post #8 in your previous thread on the same exact topic? Notice the change from ~= to ==.

http://www.mathworks.com/matlabcentral/newsreader/view_thread/284868
From: Mohammad on
"Matt Fig" <spamanon(a)yahoo.com> wrote in message <hvg8dp$9nq$1(a)fred.mathworks.com>...
> Did you read post #8 in your previous thread on the same exact topic? Notice the change from ~= to ==.
>
> http://www.mathworks.com/matlabcentral/newsreader/view_thread/284868

Oops, thanks!, I'll look it over. BTW, nice function name :)
From: John D'Errico on
"Mohammad " <jaber2(a)uni.uiuc.edu> wrote in message <hvg7hl$emv$1(a)fred.mathworks.com>...
> Hi guys.
>
> I currently have a plotting function, trail5(m,n,o) where I want to make sure that at any time m+n+o=integer. I also want to make trail5(m,n,o)=plot with values of 1 through d in stems of 1/2, 1 through g in stems of 1/2, 1 through h in stems of 1/2, in order to make many copies of my image. (I input d,g,h as a boundary)
>
> For the m+n+o=integer part, I've tried to build off a suggestion of a nested for loop:
>
> for m=1:.5:d
> for n=1:.5:g
> for o=1:.5:h
> V = n+m+o;
> if V~=floor(V)
> trail5(m,n,o) %what I want to solve for in every possible value of m,n,o
> end
> end
> end
> end
>
> Is there a simple way to fix this so that trail5(m,n,o) works, and so that m+n+o=integer?
>

Gosh. Think.

Suppose I knew the values of m and n?

Would I be able to compute EXACTLY which values of o
would assuredly generate an integer in the aggregate
value (m+n+o)?

So why not just loop over m and n?

Can you do even better? Suppose I knew the value of m?
I.e., you know that it is either already an integer, so either
both n and o must be integers, or both n and o must be
half integers.

This allows you to employ only a single loop, coupled
with two calls to meshgrid. Of course, if things are small
enough, just make one call to meshgrid, or ndgrid, and
test the sum.

John
From: Mohammad on
"Matt Fig" <spamanon(a)yahoo.com> wrote in message <hvg8dp$9nq$1(a)fred.mathworks.com>...
> Did you read post #8 in your previous thread on the same exact topic? Notice the change from ~= to ==.
>
> http://www.mathworks.com/matlabcentral/newsreader/view_thread/284868

I inserted that clause toward the end, but when I inserted values n=1.5 m=2.5 o=3.5, the program ran and the object appeared (which is what I don't want?).

Cordially, Mohammad

(here's the program I ran in MATLAB...

function trail5(d,g,h)

L = input('Please enter value of L. [L]: ');
R = input('Please enter value of R. [R]: ');
d = input('Please enter value of a. [a]: ');
g = input('Please enter value of b. [b]: ');
h = input('Please enter value of c. [c]: ');

patch('vertices',[.5*L+(sqrt(2)*R+2*L)*d .5*L+(sqrt(2)*R+2*L)*g 0+(sqrt(2)*R+2*L)*h
-.5*L+(sqrt(2)*R+2*L)*d .5*L+(sqrt(2)*R+2*L)*g 0+(sqrt(2)*R+2*L)*h
-.5*L+(sqrt(2)*R+2*L)*d -.5*L+(sqrt(2)*R+2*L)*g 0+(sqrt(2)*R+2*L)*h
..5*L+(sqrt(2)*R+2*L)*d -.5*L+(sqrt(2)*R+2*L)*g 0+(sqrt(2)*R+2*L)*h
sqrt(.5)*R+.5*L+(sqrt(2)*R+2*L)*d .5*L+(sqrt(2)*R+2*L)*g sqrt(.5)*R+(sqrt(2)*R+2*L)*h
-sqrt(.5)*R-.5*L+(sqrt(2)*R+2*L)*d .5*L+(sqrt(2)*R+2*L)*g sqrt(.5)*R+(sqrt(2)*R+2*L)*h
-sqrt(.5)*R-.5*L+(sqrt(2)*R+2*L)*d -.5*L+(sqrt(2)*R+2*L)*g sqrt(.5)*R+(sqrt(2)*R+2*L)*h
sqrt(.5)*R+.5*L+(sqrt(2)*R+2*L)*d -.5*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t(.5)*R+.5*L+(sqrt(2)*R+2*L)*g sqrt(.5)*R+L+(sqrt(2)*R+2*L)*h
-.5*L+(sqrt(2)*R+2*L)*d .5*L+(sqrt(2)*R+2*L)*g sqrt(2)*R+L+(sqrt(2)*R+2*L)*h
..5*L+(sqrt(2)*R+2*L)*d .5*L+(sqrt(2)*R+2*L)*g sqrt(2)*R+L+(sqrt(2)*R+2*L)*h
-.5*L+(sqrt(2)*R+2*L)*d -.5*L+(sqrt(2)*R+2*L)*g sqrt(2)*R+L+(sqrt(2)*R+2*L)*h
..5*L+(sqrt(2)*R+2*L)*d -.5*L+(sqrt(2)*R+2*L)*g sqrt(2)*R+L+(sqrt(2)*R+2*L)*h
],'faces',[11 9 1 2
13 20 11 6
23 21 13 15
9 19 14 5
19 20 21 22
1 5 8 4
3 4 10 12
6 2 3 7
15 7 12 18
24 23 18 17
8 16 17 10
16 14 22 24],'facecolor',[1 0 0]);

view(3)
rotate3d
axis equal

for m = 1:.5:d;
for n = 1:.5:g;
for o = 1:.5:h;
V = n+m+o;
if V == floor(V)
disp([m n o V])
trail5(m,n,o);
end
end
end
end
 |  Next  |  Last
Pages: 1 2
Prev: vrml and .mat file
Next: display image for comparison