Maple produces an error when adding positive constraints - maple

I am testing Maple 2021 on a simple system of equations in x,y,z,t:
solve({x = 1, a*z^2 = c*t*x, c*x^2 = a*y*z, d*y^2 = b*t*x, 0 < a, 0 < b, 0 < c, 0 < d}, {t, x, y, z});
The results look correct (sorry for the formatting, this is copy-pasted directly from Maple):
/[[ / (1/2) (1/2) (1/4) (1/4)
|[[ | d c c b
PIECEWISE|[[< t = -------------, x = 1, y = -------------,
|[[ | (1/2) (1/2) (1/4) (1/4)
\[[ \ a b d a
(3/4) (1/4)\ / (1/2) (1/2)
c d | | d c
z = ------------- >, < t = -------------, x = 1,
(3/4) (1/4)| | (1/2) (1/2)
a b / \ a b
(1/4) (1/4) (3/4) (1/4)\ ]
c b c d | ]
y = - -------------, z = - ------------- >],
(1/4) (1/4) (3/4) (1/4)| ]
d a a b / ]
] \
] |
And(0 < a, 0 < b, 0 < c, 0 < d)], [[], otherwise]|
] |
] /
I only want to obtain positive solution, so I add such constraint:
solve({c*x^(2)=a*y*z,d*y^(2)=b*t*x,a*z^(2)=c*t*x,x=1,a>0,b>0,c>0,d>0,x>0,y>0,z>0,t>0},{x,y,z,t});
However, I obtained an error:
Error, Got internal error in Typesetting:-Parse :
"'_Inert_DELAYLESSTHAN' is not a valid inert form"
Thanks for your help!

I do not get such an error (in displaying the result), using Maple 2021.1.
I use lprint below only so that I can paste the result in here more easily.
restart;
kernelopts(version);
Maple 2021.1, X86 64 LINUX, May 19 2021, Build ID 1539851
sol:=solve({c*x^(2)=a*y*z,d*y^(2)=b*t*x,
a*z^(2)=c*t*x, x=1,
a>0,b>0,c>0,d>0,x>0,y>0,z>0,t>0},
{x,y,z,t}):
lprint(%);
piecewise(And(0 < a,0 < b,0 < c,0 < d,0 <
d*c^2*b/(c^3*d*a*b^3)^(1/2),0 < 1/a/b
*(c^3*d*a*b^3)^(1/4),0 <
c*b/(c^3*d*a*b^3)^(1/4),0 <=
c*b/(c^3*d*a*b^3)^(1/4)),
[{t = d^(1/2)*c^(1/2)/a^(1/2)/b^(1/2), x = 1,
y = c^(1/4)*b^(1/4)/d^(1/4)/a^(1/
4), z = 1/a^(3/4)/b^(1/4)*c^(3/4)*d^(1/4)}],
And(0 < a,0 < b,0 < c,0 < d,0 < d*c
^2*b/(c^3*d*a*b^3)^(1/2),0 < 1/a/b*
(c^3*d*a*b^3)^(1/4),0 < c*b/(c^3*d*a*b^3)^(1
/4),1/a/b*(c^3*d*a*b^3)^(1/4) <
0,c*b/(c^3*d*a*b^3)^(1/4) < 0),[{t =
d*c^2*b/(c^3*d*a*b^3)^(1/2), x = 1, y =
c*b/(c^3*d*a*b^3)^(1/4), z = 1/a/b*(c^3*d*a*b^3)^
(1/4)}, {t = d*c^2*b/(c^3*d*a*b^3)^(1/2), x = 1,
y = -c*b/(c^3*d*a*b^3)^(1/4),
z = -1/a/b*(c^3*d*a*b^3)^(1/4)}],
And(0 < a,0 < b,0 < c,0 < d,0 < d*c^2*b/(c^3*d
*a*b^3)^(1/2),1/a/b*(c^3*d*a*b^3)^(1/4) <
0,c*b/(c^3*d*a*b^3)^(1/4) < 0,c*b/(c^
3*d*a*b^3)^(1/4) <= 0),[{t =
d^(1/2)*c^(1/2)/a^(1/2)/b^(1/2), x = 1, y = -c^(1/
4)*b^(1/4)/d^(1/4)/a^(1/4), z =
-1/a^(3/4)/b^(1/4)*c^(3/4)*d^(1/4)}],[])
combine(sol) assuming
a>0,b>0,c>0,d>0,x>0,y>0,z>0,t>0:
lprint(%);
[{t = (d*c/b/a)^(1/2), x = 1, y = 1/d/a*
(c*b*d^3*a^3)^(1/4), z = 1/a/b*(c^3*d*a
*b^3)^(1/4)}]

Related

Sum of rectangles in Matlab

I have a code which doesnt work the way I want to. The problem is i need a sum of all rctangles from a picture as below.
My code:
imH = size(I, 1);
imW = size(I, 2);
windowWidth = 30;
windowHeight = 30;
step = 1;
for r = 1:step:imH - windowHeight + 1
for c = 1:step:imW - windowWidth + 1
Win = I(r:r + windowHeight - 1, c:c + windowWidth - 1, :);
post =[c r windowHeight windowWidth];
I think I lack sum here
%stop = waitforbuttonpress;
subplot(121); imshow(I); title 'Image';
hold on;
rectangle('Position', pos, 'EdgeColor', 'r');
hold off;
subplot (122); imshow(W); title 'ooo';
drawnow;
pause(0.0000001);
end
end
Everything works great but I need to sum separately every rectangle values
You only need to add & in the 1st and 2nd rgb intervals as below:
matchNh = (R > 45 & R < 180) & (G > 50 & G < 185) & (B > 160 & B < 215);
matchNd = (R > 40 & R < 115) & (G > 6 & G < 80) & (B > 10 & B < 75);
Then you are doing right to count the nonzero pixels i.e.
Nh = nnz(matchNh);
Nd = nnz(matchNd);
If you want to use for more than one image , then you can use another for loop outside the two for loops e.g.
imgnames = dir('*.jpg'); % get list of jpg images in current directory
NN = length(imgnames)
%sliding window size
windowWidth = 64;
windowHeight = 64;
%step
step = 64;
Nh = 0;
Nd = 0;
for ii = 1 : NN
I = imread(imgnames(ii).name);
% your code i.e. two for loops as you have written above
imH = size(I, 1);
imW = size(I, 2);
for r = 1:step:imH - windowHeight + 1
for c = 1:step:imW - windowWidth + 1
%sliding window value
W = I(r:r + windowHeight - 1, c:c + windowWidth - 1, :);
pos =[c r windowHeight windowWidth];
R = W(:,:,1);
G = W(:,:,2);
B = W(:,:,3);
% RGB intervals for every sliding window
matchNh = (R > 45 & R < 180) & ...
(G > 50 & G < 185) & ...
(B > 160 & B < 215);
matchNd = (R > 40 & R < 115) & ...
(G > 6 & G < 80) & ...
(B > 10 & B < 75);
Nh = Nh + nnz(matchNh);
Nd = Nd + nnz(matchNd);
end
end
PIc = Nd / (Nh + Nd)
end

Generate random points - limit number per tile of total area

I am trying to create a set of random points, but limit the number in each say, 1/4th, of the total area. So imagining my x & y ranged from 0 to 2, and 0 to 2, I would only get a certain number of randomly generated points within the tile (0
So far, I thought I could just create an if statement for each tile, then if the randomly generated point falls within the tile, it gets added to a count, which then if the count exceeds or is not great enough for that tile, another point will be generated and checked. This count method doesn't seem to work, instead of each of the counts going up, I get only the count for tile 4 to increase.
n = 8;
used = [];
k = 0;
a1_count = 0;
a2_count = 0;
a3_count = 0;
a4_count = 0;
while k<n
x = rand*2;
y = rand*2;
if 0 < x < 1 && 0 < y < 1
a1_count = a1_count + 1;
end
if 1 < x < 2 && 0 < y < 1
a2_count = a2_count + 1;
end
if 0 < x < 1 && 1 < y < 2
a3_count = a3_count + 1;
end
if 1 < x < 2 && 1 < y < 2
a4_count = a4_count + 1;
end
used(end+1,:) = [x;y];
k = k+1;
end
If the counts worked correctly, I would then have a min & max, and then use an if statement to check if a count is outwith the min & max, and if so use the continue statement to go on or not.
Can anyone tell me why the count is not increasing for each area? If I run this code, I get a1_count, a2_count, a3_count = 0, while a4_count = 8, even though the points lie within the a1, a2 and a3 boundaries.
An expression of the form 0 < x < 1 needs to be written as 0 < x && x < 1.
0 < x < 1 is syntactically valid so therefore does not flag up any warning or error: it is the same as (0 < x) < 1. Note that (0 < x) is itself either 0 or 1.
This explains why 1 < x < 2 && 1 < y < 2 always evaluates to 1 and therefore a4_count is always increased: 1 < x < 2 is (1 < x) < 2 which is always 1, irrespective of the value of x. Similarly for 1 < y < 2.

if statement in MatLab environment

I used the following simple code to check the properties of elseif command in MATLAB:
x = 10;
if x < 0
y = x;
elseif 0 <= x < 2
y = 3*x;
elseif x >= 2
y = 8*x;
end
y
I would have expected the result of this to be 80 since x >= 2. But something amazing happened! The result is 30, not 80!
But why? Any ideas?
Update: when I change the code (as recommended in the answers) to
x = 10;
if x < 0
y = x;
elseif (0 <= x) && ( x < 2 )
y = 3*x;
elseif x >= 2
y = 8*x;
end
y
I get 80 as expected. It's that double condition that threw me off.
When you write
if 0 <= x < 2
you are really writing (without realizing it)
if (0 <= x) < 2
Which is evaluated as
if (true) < 2
which is true, since true evaluates to 1.
So here is what is happening, line by line:
x = 10; % x is set to 10
if x < 0 % false
y = x; % not executed
elseif 0 <= x < 2 % condition is (true) < 2, thus true
y = 3*x; % y is set to 3*x, i.e. 30
elseif x >= 2 % since we already passed a condition, this is not evaluated
y = 8*x; % skipped
end % end of composite if
y % display the value of y - it should be 30
As an aside, when you use scalars, you should really use the && operator, not the & operator. See for example What's the difference between & and && in MATLAB?
0 <= x < 2 doesn't behave as you may expect. Use (0 <= x) & (x < 2)
How does 0 <= x < 2 behave? It is evaluated from left to right. First 0 <= x gives 1 (true), and then 1 < 2 gives 1 (true). So the condition gives true, not false as you would expect.
Since the second condition in your code (0 <= x < 2) is true, you get a value 30 for y. Changing the condition to (0 <= x) & (x < 2) you get a value 80 for y.

Matlab - how to plot step function

I am having a hard time plotting a step function. The function involves is the Haar scaling function which is defind as:
ø(x) = 1 if 0 ≤ x < 1
ø(x) = 0 otherwise
I am supposed to plot the following function:
f(x) = 2ø(4x) + 2ø(4x - 1) + ø(4x - 2) - ø(4x - 3)
This is supposed to give me a plot where f = 2 on the interval 0 ≤ x < 0.5; f = 1 on the interval 0.5 ≤ x < 0.75; f = -1 on the interval 0.75 ≤ x < 1, and f = zero otherwise.
I tried the following code:
f = #(t) 2*(4*t > 0) + 2*(4*t > 1) + (4*t > 2) - (4*t > 3);
t = linspace(-2,2,100);
stairs(t,f(t))
However, this does not give me an accurate graph. So what am I doing wrong here? Any help will be greatly appreciated!
Your implementation of f only deals with half of your specification of phi.
f = #(t) 2*(4*t > 0) + 2*(4*t > 1) + (4*t > 2) - (4*t > 3);
In each of the terms applies the inequality 0 < X, rather than 0 <= X. Also nothing is done about the X < 1 inequality.
Rather than trying to make a custom version for each term, why not code up your formula directly?
phi = #(x) x >= 0 & x < 1;
f = #(x) 2*phi(4*x) + 2*phi(4*x-1) + phi(4*x - 2) - phi(4*x - 3);
it should be:
f = #(t) 2*(4*t > 0 & 4*t < 1) + 2*(4*t > 1 & 4*t < 2) + (4*t > 2 & 4*t < 3) - (4*t > 3);
Because every segment should be defined precisely with start and end values.

B-Spline Basic function Matlab recursive

I'm trying to make a B-Spline Function
first i set the variables and made the Knot vector
# cmpp.m
% Set variables
k = 3; % (8 mod 2 + 2 + 1)
p = k - 1; % Order = 2
n = 2*k - 1; % Control points = 5
l = n + p + 1; % Vector size n + p + 1 = 8
% Create the Knot vector
% Kv = [0 0 0 1 2 3 3 3] size = 8
knoten = 0; % set all knots to 0
Kv = [];
for j=1:1:l
Kv = [ Kv 0 ];
end
for i=1:1:l
if (i > n)
if (i <= n)
Kv(i) = knoten + 1;
knoten = knoten + 1;
else
Kv(i) = knoten;
end
else
Kv(i) = knoten;
end
end
then i worte a function to create the basic function
# f.m
function N = f(N,t,i,k,u,x,s)
if (u < x)
N(i,k) = ((((u-t(i)).*f(t,i,k-1,u+s,x,s)) / (t(i+k-1) - t(i))) + (((t(i+k)-u).*f(t,i+1,k-1,u+s,x,s)) / (t(i+k) - t(i+1))));
if ((u >= t(i)) && (u < t(i+1)))
N(i,1) = 1;
else
N(i,1) = 0;
end
end
end
and called it in cmpp.m
# cmpp.m
...
...
...
N = zeros(l,k);
x = (n+1) - (k-1);
s = 1;
N = [N f(N,Kv,1,k,0,x,s)];
but i get always this error in Matlab
>> cmpp
Subscripted assignment dimension mismatch.
Error in f (line 3)
N(i,k) = ((((u-t(i)).*f(t,i,k-1,u+s,x,s)) / (t(i+k-1) - t(i))) +
(((t(i+k)-u).*f(t,i+1,k-1,u+s,x,s)) / (t(i+k) - t(i+1))));
Error in cmpp (line 32)
N = [N f(N,Kv,1,k,0,x,s)]