jan

79 Reputation

5 Badges

20 years, 88 days

MaplePrimes Activity


These are replies submitted by jan

Hello, Here is a workaround that you can try. It is not pretty, but it works. First, let's create a test matrix: M:=Matrix([[x^2+y^2, x^2], [a, b], [c,d]]); Then we want to create our own list of statements from the matrix. cs := [seq(seq('Mout'[i,j]=M[i,j], i=1..2), j=1..2)]; We then optimize the set of statements. cs2 := [codegen[optimize](cs)]; Now, we want to pull out the names of all the temporary variables. Examining, the left hand sides of all the equations, we see that they contain either the temporary variable or M[i,j]. Since the temporary variables are of type symbol and M[i,j] are of type indexed, we can use indets to create a set of all temporary variables. l1 := indets(map (lhs, cs2), 'symbol'); Then we create a list of our own declarations. decl_list := [seq (sprintf ("double %a;\n", l1[i]), i=1..nops(l1))]; Then we can join them together into one string. str_decl := StringTools[Join] (decl_list); Now we can code generate the list of the statements. str_code := CodeGeneration[C] (cs2, output=string); And then we can put it all togehter. code := cat (str_decl, str_code); The variable code now contains a string with the following source code: double t1; double t2; t1 = x * x; t2 = y * y; Mout[0][0] = t1 + t2; Mout[1][0] = a; Mout[0][1] = t1; Mout[1][1] = b; Jan
Hello, Here is a workaround that you can try. It is not pretty, but it works. First, let's create a test matrix: M:=Matrix([[x^2+y^2, x^2], [a, b], [c,d]]); Then we want to create our own list of statements from the matrix. cs := [seq(seq('Mout'[i,j]=M[i,j], i=1..2), j=1..2)]; We then optimize the set of statements. cs2 := [codegen[optimize](cs)]; Now, we want to pull out the names of all the temporary variables. Examining, the left hand sides of all the equations, we see that they contain either the temporary variable or M[i,j]. Since the temporary variables are of type symbol and M[i,j] are of type indexed, we can use indets to create a set of all temporary variables. l1 := indets(map (lhs, cs2), 'symbol'); Then we create a list of our own declarations. decl_list := [seq (sprintf ("double %a;\n", l1[i]), i=1..nops(l1))]; Then we can join them together into one string. str_decl := StringTools[Join] (decl_list); Now we can code generate the list of the statements. str_code := CodeGeneration[C] (cs2, output=string); And then we can put it all togehter. code := cat (str_decl, str_code); The variable code now contains a string with the following source code: double t1; double t2; t1 = x * x; t2 = y * y; Mout[0][0] = t1 + t2; Mout[1][0] = a; Mout[0][1] = t1; Mout[1][1] = b; Jan
Saqib, I am not really sure why the Matlab code is not updated when it is edited from an external editor. However, here is what seems to work: When you enter the first Matlab command, for example
Matlab:-evalM("cd 'c:/documents and settings/user/my documents'");
Matlab command window is started. If you launch an editor from this command window, i.e. type
edit mat2map6.m
in the Matlab command window, then changes made by this editor seem to be reflected in your Maple session. Note that the Matlab editor must be launched from the Matlab command window that was started by your Maple session. Launching the editor from another Matlab session does not seem to update the code. Jan Applications Engineer, Maplesoft
Saqib, I am not really sure why the Matlab code is not updated when it is edited from an external editor. However, here is what seems to work: When you enter the first Matlab command, for example
Matlab:-evalM("cd 'c:/documents and settings/user/my documents'");
Matlab command window is started. If you launch an editor from this command window, i.e. type
edit mat2map6.m
in the Matlab command window, then changes made by this editor seem to be reflected in your Maple session. Note that the Matlab editor must be launched from the Matlab command window that was started by your Maple session. Launching the editor from another Matlab session does not seem to update the code. Jan Applications Engineer, Maplesoft
Leaving the abs out results in an effect called emboss. Convolving the image with the two matrices essentially calculates the first dreivating in the horizontal and vertical direction. This can result in both positive and negative values, depending on if we have a rising edge or falling edge.
  rising edge         falling edge
       +-------     --------+  
       |                    |
-------+                    +-------
The abs then removes the sign and treats positive and negative edges the same. Leaving the abs out results in an image with both positive and negative edges. After the pixel values have been rescalled between 0 and 1, all the rising edges (positive) will show as white and all the falling edges (negative) will show as black, while everything else will be gray. Jan Bakus Applications Engineer, Maplesoft
In my profile, I can set my interest to engineering sciences, yet in the content categories there is no Engineering sciences. The closest there is applied science. I think that it would make a lot of sense, if the "My Interests" option in the profile would have the same categories to choose from as the content categories. Jan Bakus Applications Engineer, Maplesoft
The mod function is a valid alternative to the provided Frem function. However, the mod function only works with integers, and in many applications the angles tend to come as floats. The mod function does not work in such cases. > 400. mod 360; Error, invalid argument for modp or mods
1 2 Page 2 of 2