Maple Questions and Posts

These are Posts and Questions associated with the product, Maple

Here is a procedure I wrote to apply a greek prefix to a value so that the coefficient lies between 1 and 1000.

 

applyGreekPrefix := proc(x)
	description
		"Accepts a number, and if it has units, a Greek prefix is added so that the coefficient is between 1 and 1000",
		"Values without units or a unit of muliple units are returned as-is"
	;
	local prefixes, powers, value, unit, exponent, new_value, idx, prefix, strUnit, new_unit, i, SIx, returnval;
	
	if Units:-Split(x)[2] = 1 or numelems(indets(op(2, x), 'name')) > 1 then	
		# Value has no units or consists of multiple units
		returnval := x;
	else
		# Define the SI prefixes and their corresponding powers of 10
		prefixes := ["q", "r", "y", "z", "a", "f", "p", "n", "μ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y", "R", "Q"];
		powers := [seq(i, i = -30 .. 30, 3)];
		
		# Convert to SI unit w/o prefix
		SIx := convert(x, 'system', 'SI');		
		# Separate the value and the unit
		value := evalf(op(1, SIx));
		unit := op(2, SIx);
		strUnit := convert(unit, string);  # Convert the unit to a string representation
		
		# Calculate the exponent of 10 for the value
		exponent := floor(log10(abs(value)));
		
		# Find the closest power of 10 that makes the coefficient between 1 and 1000
		idx := 0;
		for i from 1 to nops(powers) do
		   if exponent >= powers[i] then
		       idx := i;
		   end if;
		end do;
		
		# Adjust the value based on the selected prefix
		new_value := value / 10^powers[idx];
		prefix := prefixes[idx];
		# Construct the new unit using Units:-Unit if a prefix is needed
		if prefix = "" then
		   new_unit := unit; # No prefix needed, use the original unit
		else
		   new_unit := parse(StringTools:-Substitute(strUnit, "Units:-Unit(", cat("Units:-Unit(", prefix))); # Construct a new unit with the prefix
		end if;
		
		# Return the adjusted value with the new unit
		returnval := new_value * new_unit;
	end if;	
	return returnval;
end proc:
list_tests:=[0.0001*Unit('kV'), 10000*Unit('V'), 10*Unit('V'/'us'), 12334];
for test in list_tests do
	print (test, "becomes", applyGreekPrefix(test));
end do;

 

I have some library program files written using Maple 11 (or before).

I can read and use the file programs and they have worked fine for many years.

But I would like to actually see the programming commands that are buried within with a view to modification, so, according to the Maple "Help" file, I tried the following command sequence:

***********************************************************

restart;
interface(echo=4,quiet=false);
interface(echo);
interface(quiet);
                            1, false

                               4

                             false

read "C:\\Program Files (x86)\\Maple 11\\test3.m";

**************************************************************************

But there is no echo.

So, how do I read (and modify) these files?

Thank you

How can I check if a name has been used/entered already but was not assigned to a value

The variable palette only lists assigned names.

I tried unames() but this lists all unassigned names. A 'user' option (which filters for user-assigned names) as in anames() does not seem to exist.

One of my failed attempts (in 1D-Math):

restart;
unames():
initial_unames := {%}:
new_name;
{unames()} minus initial_unames; # should ideally return a reduced set containing new_name;
has(%,new_name)

What else can be done? (I am probably overlooking something very simple.)

For a right triangle with two legs of the right triangle a and b, draw three circles with radius r and one ellipse as shown in the diagram (the major axis of the ellipse is parallel to the hypotenuse of the right triangle). Find a relationship between a, b, and r