How to solve four unknown variables with four equations, but for more complicated input? - maxima

I'm trying to solve four unknown variables x_Trag, y_Trag, x_Zug, y_Zug with four equations eqx, eqy, Py_Trag, Py_Zug. Sadly only the easy testcase is working.
Here's the Wxmaxima paste:
(%i1) kill(all); load(ezunits);
Warning: Can set maxima's working directory but cannot change it during the maxima session :
(%o0) done
(%o1) "C:/maxima-5.44.0/share/maxima/5.44.0/share/ezunits/ezunits.mac"
1 easy values work
1.1 vars
(%i2) x_GG: 1`mm;
(x_GG) 1 ` mm
(%i3) y_GG: 18`mm;
(y_GG) 18 ` mm
(%i4) L_HR: 5`mm;
(L_HR) 5 ` mm
(%i5) L_Trag: 5`mm;
(L_Trag) 5 ` mm
(%i6) L_Zug: 15`mm;
(L_Zug) 15 ` mm
(%i7) x_HR: 4`mm;
(x_HR) 4 ` mm
(%i8) y_HR: 3`mm;
(y_HR) 3 ` mm
1.2 equations
(%i9) eqx: x_Zug=x_GG+x_HR+x_Trag;
(eqx) x_Zug=x_Trag+5 ` mm
(%i10) eqy: y_GG=y_HR+y_Zug+y_Trag;
(eqy) 18 ` mm=y_Zug+y_Trag+3 ` mm
(%i11) Py_Trag: L_Trag^2=x_Trag^2+y_Trag^2;
(Py_Trag) 25 ` mm^2=y_Trag^2+x_Trag^2
(%i12) Py_Zug: L_Zug^2=x_Zug^2+y_Zug^2;
(Py_Zug) 225 ` mm^2=y_Zug^2+x_Zug^2
1.3 solving works
(%i13) res: dimensionally(solve([eqx, eqy, Py_Trag, Py_Zug], [x_Trag, y_Trag, x_Zug, y_Zug]))[1];
(res) [x_Trag=4 ` mm,y_Trag=3 ` mm,x_Zug=9 ` mm,y_Zug=12 ` mm]
2 but not the ones I need
2.1 vars
(%i14) x_GG: 2`mm;
(x_GG) 2 ` mm
(%i15) y_GG: 193`mm;
(y_GG) 193 ` mm
(%i16) L_HR: 46`mm;
(L_HR) 46 ` mm
(%i17) L_Trag: 50`mm;
(L_Trag) 50 ` mm
(%i18) L_Zug: 190`mm;
(L_Zug) 190 ` mm
(%i19) x_HR: 46*cos((149*%pi-360*acos(1/3))/360) ` mm;
(x_HR) 46*cos((149*%pi-360*acos(1/3))/360) ` mm
(%i20) y_HR: 46*sin((149*%pi-360*acos(1/3))/360) ` mm;
(y_HR) 46*sin((149*%pi-360*acos(1/3))/360) ` mm
2.2 equations
(%i21) eqx: x_Zug=x_GG+x_HR+x_Trag;
(eqx) x_Zug=x_Trag+(46*cos((149*%pi-360*acos(1/3))/360)+2) ` mm
(%i22) eqy: y_GG=y_HR+y_Zug+y_Trag;
(eqy) 193 ` mm=y_Zug+y_Trag+46*sin((149*%pi-360*acos(1/3))/360) ` mm
(%i23) Py_Trag: L_Trag^2=x_Trag^2+y_Trag^2;
(Py_Trag) 2500 ` mm^2=y_Trag^2+x_Trag^2
(%i24) Py_Zug: L_Zug^2=x_Zug^2+y_Zug^2;
(Py_Zug) 36100 ` mm^2=y_Zug^2+x_Zug^2
2.3 solving takes very long, but dosen't find a solution
(%i26) res: dimensionally(solve([eqx, eqy, Py_Trag, Py_Zug], [x_Trag, y_Trag, x_Zug, y_Zug])); float(%);
(res) []
(%o26) []
wxm-file, which should be better for pasting:
/* [wxMaxima batch file version 1] [ DO NOT EDIT BY HAND! ]*/
/* [ Created with wxMaxima version 21.02.0 ] */
/* [wxMaxima: input start ] */
kill(all); load(ezunits);
/* [wxMaxima: input end ] */
/* [wxMaxima: section start ]
easy values work
[wxMaxima: section end ] */
/* [wxMaxima: subsect start ]
vars
[wxMaxima: subsect end ] */
/* [wxMaxima: input start ] */
x_GG: 1`mm;
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
y_GG: 18`mm;
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
L_HR: 5`mm;
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
L_Trag: 5`mm;
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
L_Zug: 15`mm;
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
x_HR: 4`mm;
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
y_HR: 3`mm;
/* [wxMaxima: input end ] */
/* [wxMaxima: subsect start ]
equations
[wxMaxima: subsect end ] */
/* [wxMaxima: input start ] */
eqx: x_Zug=x_GG+x_HR+x_Trag;
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
eqy: y_GG=y_HR+y_Zug+y_Trag;
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
Py_Trag: L_Trag^2=x_Trag^2+y_Trag^2;
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
Py_Zug: L_Zug^2=x_Zug^2+y_Zug^2;
/* [wxMaxima: input end ] */
/* [wxMaxima: subsect start ]
solving works
[wxMaxima: subsect end ] */
/* [wxMaxima: input start ] */
res: dimensionally(solve([eqx, eqy, Py_Trag, Py_Zug], [x_Trag, y_Trag, x_Zug, y_Zug]))[1];
/* [wxMaxima: input end ] */
/* [wxMaxima: section start ]
but not the ones I need
[wxMaxima: section end ] */
/* [wxMaxima: subsect start ]
vars
[wxMaxima: subsect end ] */
/* [wxMaxima: input start ] */
x_GG: 2`mm;
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
y_GG: 193`mm;
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
L_HR: 46`mm;
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
L_Trag: 50`mm;
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
L_Zug: 190`mm;
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
x_HR: 46*cos((149*%pi-360*acos(1/3))/360) ` mm;
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
y_HR: 46*sin((149*%pi-360*acos(1/3))/360) ` mm;
/* [wxMaxima: input end ] */
/* [wxMaxima: subsect start ]
equations
[wxMaxima: subsect end ] */
/* [wxMaxima: input start ] */
eqx: x_Zug=x_GG+x_HR+x_Trag;
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
eqy: y_GG=y_HR+y_Zug+y_Trag;
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
Py_Trag: L_Trag^2=x_Trag^2+y_Trag^2;
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
Py_Zug: L_Zug^2=x_Zug^2+y_Zug^2;
/* [wxMaxima: input end ] */
/* [wxMaxima: subsect start ]
solving takes very long, but dosen't find a solution
[wxMaxima: subsect end ] */
/* [wxMaxima: input start ] */
res: dimensionally(solve([eqx, eqy, Py_Trag, Py_Zug], [x_Trag, y_Trag, x_Zug, y_Zug])); float(%);
/* [wxMaxima: input end ] */
/* Old versions of Maxima abort on loading files that end in a comment. */
"Created with wxMaxima 21.02.0"$

I tried some different approaches and some work better than others. What eventually worked was to apply eliminate to reduce the four equations to two, and then apply solve to that. Of course solve should work by itself, and it's a shortcoming that it fails to solve the original set of equations.
Here's my script which you can run via maxima --batch. The solutions which it finds are pretty messy, so I guess you'll have to decide if they're practically useful. One thing to try to make it a little cleaner is to write, say, cos_a and sin_a instead of cos(...) and sin(...). Then you can substitute for cos_a and sin_a after solving.
linel: 65 $
load(ezunits);
x_GG: 2`mm;
y_GG: 193`mm;
L_HR: 46`mm;
L_Trag: 50`mm;
L_Zug: 190`mm;
x_HR: 46*cos((149*%pi-360*acos(1/3))/360) ` mm;
y_HR: 46*sin((149*%pi-360*acos(1/3))/360) ` mm;
eqx: x_Zug=x_GG+x_HR+x_Trag;
eqy: y_GG=y_HR+y_Zug+y_Trag;
Py_Trag: L_Trag^2=x_Trag^2+y_Trag^2;
Py_Zug: L_Zug^2=x_Zug^2+y_Zug^2;
dimensionally (eliminate ([eqx, eqy, Py_Trag, Py_Zug], [x_Trag, x_Zug]));
solutions_y: dimensionally (solve (%, [y_Trag, y_Zug]));
grind (solutions_y);
solutions_y_numerical: float (solutions_y);
solutions_y_numerical_filtered: sublist (%, lambda ([e], every (lambda ([x], qty(x) > 0), map (rhs, e))));
dimensionally (eliminate ([eqx, eqy, Py_Trag, Py_Zug], [y_Trag, y_Zug]));
solutions_x: dimensionally (solve (%, [x_Trag, x_Zug]));
grind (solutions_x);
solutions_x_numerical: float (solutions_x);
solutions_x_numerical_filtered: sublist (%, lambda ([e], every (lambda ([x], qty(x) > 0), map (rhs, e))));
solutions_numerical_filtered: append (solutions_x_numerical_filtered[1], solutions_y_numerical_filtered[1]);
subst (%, [eqx, eqy, Py_Trag, Py_Zug]), numer;
The problem setup is the same as yours, the new stuff is from eliminate onwards. The numerical solution printed towards the end is
[x_Trag = 44.09785089359991 ` mm,
x_Zug = 91.98740317879643 ` mm,
y_Trag = 23.56649202927388 ` mm,
y_Zug = 166.2477598538445 ` mm]
(I was assuming that the solutions with negative quantities are nonphysical -- I guess you can say for sure.)
I also tried to_poly_solve, which is included with Maxima; it wasn't able to solve the original equations.
I am working with Maxima 5.44. I didn't try it on any earlier versions.

Related

Netlogo ecosystem model die command

I am trying to simulate what happens to vultures if they randomly stumble upon a carcass that has been poisoned by poachers. The poisoned carcass needs to be random. I also need to plot the deaths, so do i need to set up a dead/poisoned state in order to plot the deaths, do I need to code a to die section. Im not sure. TIA
to go
; repeat 10800 [
ask vultures
[
if state = "searching" [ search-carcasses ]
if state = "following" [follow-leaders-find-carcasses]
if state = "searching"
[ if random-float 1 < ( 1 / 360 )
[ ifelse random 2 = 0
[ rt 45 ]
[ lt 45 ] ] ]
if state != "feeding"
[ fd 0.009 ]
if state = "leader" [set time-descending time-descending + 1]
if mycarcass != 0
[ if distance mycarcass <= 0.009
[ set state "feeding"
ask mycarcass
[ set occupied? "yes" ] ] ] if state = "feeding" [
ask mycarcass
[if poisoned? = "yes"
[set state "poisoned"] ] ] if state = "poisoned" [die] ] tick ; ]

Convert partial number to written word form in Google Sheets (e.g. 1300 to 1.3 thousand)? [duplicate]

is there a way how to custom format ridiculously large numbers (at least up to 10^100 in both ways) in google sheets:
thousands > K
millions > M
billions > B
trillions > T
etc...
negative quadrillions > Q
decillions > D
either via:
internal custom number formatting
formula (array formula ofc)
script similar to this one just extended to cover more ground
10000.1 10.0K
100 100.0
1000 1.0K
10000 10.0K
-100000 -100.0K
45646454 45.6M
5654894844216 5.7T
4655454544 4.7B
46546465455511 46.5T
-46546465455511 -46.5T
4654646545551184854556546454454400000000000000000000000000010000000 4.7U
-1000.9999 -1.0K
-100.8989 -100.9
-20.354 -20.4
1.03 1.0
22E+32 2.2D
internal custom number formatting solution:
sadly, the internal formatting in google sheets is by default able to work with only 3 types of numbers:
positive (1, 2, 5, 10, ...)
negative (-3, -9, -7, ...)
zero (0)
this can be tweaked to show custom formatting like thousands K, millions M and regular small numbers:
[>999999]0.0,,"M";[>999]0.0,"K";0
or only thousands K, millions M, billions B
[<999950]0.0,"K";[<999950000]0.0,,"M";0.0,,,"B"
or only negative thousands K, negative millions M, negative billions B
[>-999950]0.0,"K";[>-999950000]0.0,,"M";0.0,,,"B"
or only millions M, billions B, trillions T:
[<999950000]0.0,,"M";[<999950000000]0.0,,,"B";0.0,,,,"T"
or only numbers from negative million M to positive million M:
[>=999950]0.0,,"M";[<=-999950]0.0,,"M";0.0,"K"
but you always got only 3 slots you can use, meaning that you can't have trillions as the 4th type/slot. fyi, the 4th slot exists, but it's reserved for text. to learn more about internal formatting in google sheets see:
https://developers.google.com/sheets/api/guides/formats#meta_instructions
https://www.benlcollins.com/spreadsheets/google-sheets-custom-number-format/
formula (array formula) solution:
the formula approach is more versatile... first, you will need to decide on the system/standard you want to use (American, European, Greek, International, Unofficial, etc...):
en.wikipedia.org/wiki/Names_of_large_numbers
en.wikipedia.org/wiki/Metric_prefix
simple.wikipedia.org/wiki/Names_for_large_numbers
home.kpn.nl/vanadovv/BignumbyN
after that try:
=INDEX(REGEXREPLACE(IFNA(TEXT(A:A/10^(VLOOKUP(LEN(TEXT(INT(ABS(A:A)), "0"))-1,
SEQUENCE(35, 1,, 3), 1, 1)), "#.0")&VLOOKUP(ABS(A:A)*1, {{10^SEQUENCE(34, 1, 3, 3)},
{"K "; "M "; "B "; "T "; "Qa "; "Qi "; "Sx "; "Sp "; "O "; "N "; "D "; "Ud ";
"Dd "; "Td "; "Qad"; "Qid"; "Sxd"; "Spd"; "Od "; "Nd "; "V "; "Uv "; "Dv "; "Tv ";
"Qav"; "Qiv"; "Sxv"; "Spv"; "Ov "; "Nv "; "Tr "; "Ut "; "Dt "; "Tt "}}, 2, 1),
IF(ISBLANK(A:A),, TEXT(A:A, "0.0 "))), "^0\.0 $", "0 "))
works with positive numbers
works with negative numbers
works with zero
works with decimal numbers
works with numeric values
works with plain text numbers
works with scientific notations
works with blank cells
works up to googol 10^104 in both ways
extra points if you are interested in how it works...
let's start with virtual array {{},{}}. SEQUENCE(34, 1, 3, 3) will give us 34 numbers in 1 column starting from number 3 with the step of 3 numbers:
these will be used as exponents while rising 10 on the power ^
so our virtual array will be:
next, we insert it as the 2nd argument of VLOOKUP where we check ABS absolute values (converting negative values into positive) of A column multiplied by *1 just in case values of A column are not numeric. via VLOOKUP we return the second 2 column and as the 4th argument, we use approximate mode 1
numbers from -999 to 999 will intentionally error out at this point so we could later use IFNA to "fix" our errors with IF(A:A=IF(,,),, TEXT(A:A, "#.0 ")) translated as: if range A:A is truly empty ISBLANK output nothing, else format A column with provided pattern #.0 eg. if cell A5 = empty, the output will be blank cell... if -999 < A5=50 < 999 the output will be 50.0
and the last part:
TEXT(A:A/10^(VLOOKUP(LEN(TEXT(INT(ABS(A:A)), "0"))-1,
SEQUENCE(35, 1,, 3), 1, 1)), "#.0")
ABS(A:A) to convert negative numbers into positive. INT to remove decimal numbers if any. TEXT(, "0") to convert scientific notations 3E+8 into regular numbers 300000000. LEN to count digits. -1 to correct for base10 notation. VLOOKUP above-constructed number in SEQUENCE of 35 numbers in 1 column, this time starting from number 0 ,, with the step of 3 numbers. return via VLOOKUP the first 1 column (eg. the sequence) in approximate mode 1 of vlookup. insert this number as exponent when rising the 10 on power ^. and take values in A column and divide it by the above-constructed number 10 raised on the power ^ of a specific exponent. and lastly, format it with TEXT as #.0
to convert ugly 0.0 into beautiful 0 we just use REGEXREPLACE. and INDEX is used instead of the longer ARRAYFORMULA.
sidenote: to remove trailing spaces (which are there to add nice alignment lol) either remove them from the formula or use TRIM right after INDEX.
script solution:
gratitude to #TheMaster for covering this
here is a mod of it:
/**
* formats various numbers according to the provided short format
* #customfunction
* #param {A1:C100} range a 2D array
* #param {[X1:Y10]} database [optional] a real/virtual 2D array
* where the odd column holds exponent of base 10
* and the even column contains format suffixes
* #param {[5]} value [optional] fix suffix to fixed length
* by padding spaces (only if the second parameter exists)
*/
// examples:
// =CSF(A1:A)
// =CSF(2:2; X5:Y10)
// =CSF(A1:3; G10:J30)
// =CSF(C:C; X:Y; 2) to use custom alignment
// =CSF(C:C; X:Y; 0) to remove alignment
// =INDEX(TRIM(CSF(A:A))) to remove alignment
// =CSF(B10:D30; {3\ "K"; 4\ "TK"}) for non-english sheets
// =CSF(E5, {2, "deci"; 3, "kilo"}) for english sheets
// =INDEX(IF(ISERR(A:A*1); A:A; CSF(A:A))) to return non-numbers
// =INDEX(IF((ISERR(A:A*1))+(ISBLANK(A:A)), A:A, CSF(A:A*1))) enforce mode
function CSF(
range,
database = [
[3, 'K' ], //Thousand
[6, 'M' ], //Million
[9, 'B' ], //Billion
[12, 'T' ], //Trillion
[15, 'Qa' ], //Quadrillion
[18, 'Qi' ], //Quintillion
[21, 'Sx' ], //Sextillion
[24, 'Sp' ], //Septillion
[27, 'O' ], //Octillion
[30, 'N' ], //Nonillion
[33, 'D' ], //Decillion
[36, 'Ud' ], //Undecillion
[39, 'Dd' ], //Duodecillion
[42, 'Td' ], //Tredecillion
[45, 'Qad'], //Quattuordecillion
[48, 'Qid'], //Quindecillion
[51, 'Sxd'], //Sexdecillion
[54, 'Spd'], //Septendecillion
[57, 'Od' ], //Octodecillion
[60, 'Nd' ], //Novemdecillion
[63, 'V' ], //Vigintillion
[66, 'Uv' ], //Unvigintillion
[69, 'Dv' ], //Duovigintillion
[72, 'Tv' ], //Trevigintillion
[75, 'Qav'], //Quattuorvigintillion
[78, 'Qiv'], //Quinvigintillion
[81, 'Sxv'], //Sexvigintillion
[84, 'Spv'], //Septenvigintillion
[87, 'Ov' ], //Octovigintillion
[90, 'Nv' ], //Novemvigintillion
[93, 'Tr' ], //Trigintillion
[96, 'Ut' ], //Untrigintillion
[99, 'Dt' ], //Duotrigintillion
[100, 'G' ], //Googol
[102, 'Tt' ], //Tretrigintillion or One Hundred Googol
],
value = 3
) {
if (
database[database.length - 1] &&
database[database.length - 1][0] !== 0
) {
database = database.reverse();
database.push([0, '']);
}
const addSuffix = num => {
const pad3 = (str = '') => str.padEnd(value, ' ');
const decim = 1 // round to decimal places
const separ = 0 // separate number and suffix
const anum = Math.abs(num);
if (num === 0)
return '0' + ' ' + ' '.repeat(separ) + ' '.repeat(decim) + pad3();
if (anum > 0 && anum < 1)
return String(num.toFixed(decim)) + ' '.repeat(separ) + pad3();
for (const [exp, suffix] of database) {
if (anum >= Math.pow(10, exp))
return `${(num / Math.pow(10, exp)).toFixed(decim)
}${' '.repeat(separ) + pad3(suffix)}`;
}
};
return customFunctionRecurse_(
range, CSF, addSuffix, database, value, true
);
}
function customFunctionRecurse_(
array, mainFunc, subFunc, ...extraArgToMainFunc
) {
if (Array.isArray(array))
return array.map(e => mainFunc(e, ...extraArgToMainFunc));
else return subFunc(array);
}
sidenote 1: this script does not need to be authorized priorly to usage
sidenote 2: cell formatting needs to be set to Automatic or Number otherwise use enforce mode
extra:
convert numbers into plain text strings/words
convert array of numbers into plain text strings/words
convert custom formatted numbers into numeric numbers/values
convert text string datetime into duration value
convert text string formatted numbers into duration
convert your age into years-months-days
For almost all practical purposes we can use Intl compact format to achieve this functionality.
/**
* Utility function needed to recurse 2D arrays
*/
function customFunctionRecurse_(
array,
mainFunc,
subFunc,
...extraArgToMainFunc
) {
if (Array.isArray(array))
return array.map(e => mainFunc(e, ...extraArgToMainFunc));
else return subFunc(array);
}
/**
* Simple custom formating function using Intl
* #see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat
* #customfunction
* #author TheMaster https://stackoverflow.com/users/8404453
* #param {A1:D2} numArr A 2D array
* #returns {String[][]}Compact Intl formatted 2D array
*/
function format(numArr) {
const cIntl = new Intl.NumberFormat('en-GB', {
notation: 'compact',
compactDisplay: 'short',
});
return customFunctionRecurse_(numArr, format, (num) => cIntl.format(num));
}
But for extreme ends or custom formatting, We need to use a custom script:
/**
* Formats various numbers according to the provided format
* #customfunction
* #author TheMaster https://stackoverflow.com/users/8404453
* #param {A1:D2} numArr A 2D array
* #param {X1:Y2} formatArr [optional] A format 2D real/virtual array
* with base 10 power -> suffix mapping
* eg: X1:3 Y1:K represents numbers > 10^3 should have a K suffix
* #param {3} suffixPadLength [optional] Fix suffix to fixed length by padding spaces
* #returns {String[][]} Formatted 2D array
*/
function customFormat(
numArr,
formatArr = [
/**This formatArr array is provided by
* by player0 https://stackoverflow.com/users/5632629/
* #see https://stackoverflow.com/questions/69773823#comment123503634_69809210
*/
[3, 'K'], //Thousand
[6, 'M'], //Million
[9, 'B'], //Billion
[12, 'T'], //Trillion
[15, 'Qa'], //Quadrillion
[18, 'Qi'], //Quintillion
[21, 'Sx'], //Sextillion
[24, 'Sp'], //Septillion
[27, 'O'], //Octillion
[30, 'N'], //Nonillion
[33, 'D'], //Decillion
[36, 'Ud'], //Undecillion
[39, 'Dd'], //Duodecillion
[42, 'Td'], //Tredecillion
[45, 'Qad'], //Quattuordecillion
[48, 'Qid'], //Quindecillion
[51, 'Sxd'], //Sexdecillion
[54, 'Spd'], //Septendecillion
[57, 'Od'], //Octodecillion
[60, 'Nd'], //Novemdecillion
[63, 'V'], //Vigintillion
[66, 'Uv'], //Unvigintillion
[69, 'Dv'], //Duovigintillion
[72, 'Tv'], //Trevigintillion
[75, 'Qav'], //Quattuorvigintillion
[78, 'Qiv'], //Quinvigintillion
[81, 'Sxv'], //Sexvigintillion
[84, 'Spv'], //Septenvigintillion
[87, 'Ov'], //Octovigintillion
[90, 'Nv'], //Novemvigintillion
[93, 'Tr'], //Trigintillion
[96, 'Ut'], //Untrigintillion
[99, 'Dt'], //Duotrigintillion
[102, 'G'], //Googol
],
suffixPadLength = 3,
inRecursion = false
) {
if (!inRecursion) {
formatArr = formatArr.reverse();
formatArr.push([0, '']);
}
const addSuffix = num => {
const pad3 = (str = '') => str.padEnd(suffixPadLength, ' '); //pad 3 spaces if necessary
const anum = Math.abs(num);
if (num === 0) return '0' + pad3();
if (anum > 0 && anum < 1) return String(num.toFixed(2)) + pad3();
for (const [exp, suffix] of formatArr) {
if (anum >= Math.pow(10, exp))
return `${(num / Math.pow(10, exp)).toFixed(2)}${pad3(suffix)}`;
}
};
return customFunctionRecurse_(
numArr,
customFormat,
addSuffix,
formatArr,
suffixPadLength,
true
);
}
Usage:
=CUSTOMFORMAT(A1:A5,{{3,"k"};{10,"G"}})
Tells custom function to use k for numbers>10^3 and G for 10^10
Illustration:
/*<ignore>*/console.config({maximize:true,timeStamps:false,autoScroll:false});/*</ignore>*/
/**
* Utility function needed to map 2D arrays
*/
function customFunctionRecurse_(array, mainFunc, subFunc, extraArgToMainFunc) {
if (Array.isArray(array))
return array.map((e) => mainFunc(e, extraArgToMainFunc));
else return subFunc(array);
}
/**
* Simple custom formating function using Intl
* #see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat
* #customfunction
* #param {A1:D2} A 2D array
* #returns {String[][]}Compact Intl formatted 2D array
*/
function format(numArr) {
const cIntl = new Intl.NumberFormat('en-GB', {
notation: 'compact',
compactDisplay: 'short',
});
return customFunctionRecurse_(numArr, format, (num) => cIntl.format(num));
}
/**
* Formats various numbers according to the provided format
* #customfunction
* #param {A1:D2} A 2D array
* #param {X1:Y2=} [optional] A format 2D real/virtual array
* with base 10 power -> suffix mapping
* eg: X1:3 Y1:K represents numbers > 10^3 should have a K suffix
* #returns {String[][]} Formatted 2D array
*/
function customFormat(
numArr,
formatArr = [
//sample byte => kb formatting
[3, 'kb'],
[6, 'mb'],
[9, 'gb'],
[12, 'tb'],
]
) {
//console.log({ numArr, formatArr });
if (
formatArr[formatArr.length - 1] &&
formatArr[formatArr.length - 1][0] !== 0
) {
formatArr = formatArr.reverse();
formatArr.push([0, '']);
}
const addSuffix = (num) => {
const anum = Math.abs(num);
if (num === 0) return '0.00';
if (anum > 0 && anum < 1) return String(num.toFixed(2));
for (const [exp, suffix] of formatArr) {
if (anum >= Math.pow(10, exp))
return `${(num / Math.pow(10, exp)).toFixed(2)}${suffix}`;
}
};
return customFunctionRecurse_(numArr, customFormat, addSuffix, formatArr);
}
console.log(
customFormat([
[
0,
1000,
153,
12883255,
235688235123,
88555552233355888,
-86555,
0.8523588055,
Math.pow(10, 15),
],
])
);
<!-- https://meta.stackoverflow.com/a/375985/ --> <script src="https://gh-canon.github.io/stack-snippet-console/console.min.js"></script>
sometimes when we deal with nuclear physics we need to shorten the time so this is how:
=INDEX(IF(ISBLANK(A2:A),,TEXT(TRUNC(TEXT(IF(A2:A*1<1,
TEXT(A2:A*1, "0."&REPT(0, 30))*VLOOKUP(A2:A*1, {SORT({0; 1/10^SEQUENCE(9, 1, 3, 3)}),
{0; 10^SORT(SEQUENCE(9, 1, 3, 3), 1,)}}, 2, 1), TEXT(A2:A*1, REPT(0, 30))/
VLOOKUP(A2:A*1, TEXT({1; 60; 3600; 86400; 31536000; 31536000*10^SEQUENCE(8, 1, 3, 3)},
{"#", "#"})*1, 2, 1)), "0."&REPT("0", 30)), 3), "0.000")&" "&
VLOOKUP(A2:A*1, {SORT({0; 1/10^SEQUENCE(9, 1, 3, 3);
{1; 60; 3600; 86400; 31536000}; 31536000*10^SEQUENCE(8, 1, 3, 3)}), FLATTEN(SPLIT(
"s ys zs as fs ps ns μs ms s m h d y ky My Gy Ty Py Ey Zy Yy", " ",,))}, 2, 1)))
it's a simple conversion from seconds into abbreviation utilizing the International System of Units where:
in seconds
____________________________________
ys = yoctosecond = 0.000000000000000000000001
zs = zeptosecond = 0.000000000000000000001
as = attosecond = 0.000000000000000001
fs = femtosecond = 0.000000000000001
ps = pikosecond = 0.000000000001
ns = nanosecond = 0.000000001
μs = microsecond = 0.000001
ms = millisecond = 0.001
s = second = 1
m = minute = 60
h = hour = 3600
d = day = 86400
y = year = 31536000
ky = kiloyear = 31536000000
My = megayear = 31536000000000
Gy = gigayear = 31536000000000000
Ty = terayear = 31536000000000000000
Py = petayear = 31536000000000000000000
Ey = exayear = 31536000000000000000000000
Zy = zettayear = 31536000000000000000000000000
Yy = yottayear = 31536000000000000000000000000000

Equation not fully solved for

I've been trying to solve an equation for a 2D vector P.
But after solve there are still some P on the rhs.
Does this mean Maxima can't do it or I've done something wrong?
Here is it:
load("vect");
declare(".", commutative);
declare(P, nonscalar);
declare([v1,V1,r1], nonscalar);
declare([v2,V2,r2], nonscalar);
declare([w1,W1,m1,I1,w2,W2,m2,I2], scalar);
/* Revolute Constraint */
constraint: v2 + (w2~r2) - (v1 + (w1~r1)) = 0$
/* Velocities after impulse P */
eq1: v1 = V1 - P/m1$
eq2: w1 = W1 - (r1~P) / I1$
eq3: v2 = V2 + P/m2$
eq4: w2 = W2 + (r2~P) / I2$
eq: subst([eq1,eq2,eq3,eq4], constraint)$
solve(eq, P);
(I'm trying to get an equation for an impulse that satisfies the constraint.
I'm following Dirk Gregorius' 2nd post here: https://gamedev.net/forums/topic/469531-revolute-joint-usingimpulses/4086845)
I think I've worked out the details. I had to do some stuff by hand, and Maxima was mostly just checking that I did it correctly. If the goal is just to get to a solution, I guess that's okay.
Here's my script. You can execute this via: maxima --batch=foo.mac where foo.mac is the name of the script.
/* adapted from: https://stackoverflow.com/questions/69700162/equation-not-fully-solved
*/
load("vect");
/* I don't want to reorder arguments of cross product. */
remrule ("~", ?\~rule4);
/* I do want to flatten noncommutative multiplication.
* (It appears that's disabled by vect; ordinarily it happens by default.)
*/
dotassoc: true $
declare(P, nonscalar);
declare([v1,w1,V1,W1,r1], nonscalar);
declare([v2,w2,V2,W2,r2], nonscalar);
declare([m1,I1,m2,I2], scalar);
/* Revolute Constraint */
constraint: v2 - (r2~w2) - (v1 - (r1~w1)) = 0$
/* Velocities after impulse P */
eq1: v1 = V1 - P/m1$
eq2: w1 = W1 - (r1~P) / I1$
eq3: v2 = V2 + P/m2$
eq4: w2 = W2 + (r2~P) / I2$
eq: subst([eq1,eq2,eq3,eq4], constraint);
A(a) := matrix([0, -a[3], a[2]], [a[3], 0, -a[1]], [-a[2], a[1], 0]);
eqa: ev (eq, (u~v) := 'A(u).v);
matchdeclare (pp, lambda ([e], not freeof(P, e)));
matchdeclare (qq, lambda ([e], freeof(P, e)));
defrule (rp, pp + qq = 0, pp = -qq);
eqa1: expand (eqa);
eqa2: apply1 (eqa1, rp);
matchdeclare (aa, lambda ([e], matrixp(e) or listp(e)));
tellsimpafter (I(aa), ident (length (aa)));
matchdeclare ([aa, bb], all);
tellsimpafter (I(aa) . bb, bb);
tellsimpafter (aa . I(bb), aa);
M: -(1/I2)*'A(r2).'A(r2) - (1/I1)*'A(r1).'A(r1) + (1/m2)*I(P) + (1/m1)*I(P);
N: 'A(r2).W2 - 'A(r1).W1 - V2 + V1;
eqa2_factored: M . P = N;
expand (eqa2_factored);
?resimplify (%);
if % # eqa2 then error ("tried to factor eqa2, but something went wrong.");
solution: P = M^^-1 . N;
/* EXAMPLE: */
I1: 20 $
I2: 3 $
m1: 100 $
m2: 12 $
V1: [17, 19, -23] $
V2: [-5, -3, 11] $
W1: [8, 4, 14] $
W2: [-6, -16, 24 ] $
r1: [1/2, 2/3, 3/4] $
r2: [5, 7, 3] $
/* note various subterfuges to ensure evaluation with stated values */
example_M: ev (subst (I(P) = ident(3), M), nouns);
example_N: ev (N, nouns);
example_P: example_M^^-1 . example_N;
subst (P = example_P, ev (eqa2, eval, nouns));
if lhs(%) = rhs(%)
then print ("TEST PASSED: lhs = rhs")
else error ("TEST FAILED: lhs # rhs");
If you need to evaluate P for different parameters r1, r2, etc., my advice is to evaluate matrix M and vector N with whatever values you want to plug in, and then solve the equation P = M^^-1 . N. An explicit solution is probably going to be pretty messy.
Following Robert Dodier's advice, I broke up all the vectors and solved for P[1] and P[2] individually.
I've got something that gives me an answer but now how can I get it into nice vector form?
Here it is:
load("vect");
declare(".", commutative);
declare(P, nonscalar);
declare([v1,V1,r1], nonscalar);
declare([v2,V2,r2], nonscalar);
declare([w1,W1,m1,I1], scalar);
declare([w2,W2,m2,I2], scalar);
cross_scalar_vector(s,v) := [-s*v[2], s*v[1]]$
/* Revolute Constraint on Linear Velocity */
constraint: v2 + cross_scalar_vector(w2,r2) - (v1 + cross_scalar_vector(w1,r1)) = [0,0]$
/* Sub in velocities after impulse P. */
post_velocities: [
v1 = V1 - P/m1,
w1 = W1 - (r1~P) / I1,
v2 = V2 + P/m2,
w2 = W2 + (r2~P) / I2
]$
constraint: subst(post_velocities, constraint)$
/* Break up the remaining vectors for solve. */
vectors: [
P = [P[1], P[2]],
V1 = [V1[1], V1[2]],
r1 = [r1[1], r1[2]],
V2 = [V2[1], V2[2]],
r2 = [r2[1], r2[2]]
]$
constraint: subst(vectors, constraint)$
/* Break up vector constraint into x and y constraint for solve. */
xconstraint: lhs(constraint)[1] = 0$
yconstraint: lhs(constraint)[2] = 0$
/* Not sure why we need to do this again? */
xconstraint: subst(vectors, xconstraint)$
yconstraint: subst(vectors, yconstraint)$
/* Expand cross products for solve. */
xconstraint: express(xconstraint)$
yconstraint: express(yconstraint)$
solve([xconstraint,yconstraint], [P[1],P[2]]);

Coeficient Matrix with Maxima of taylor series

I am trying to get the coeficient matrix of the following taylor series expansion
(%i47) SS: taylor( matrix( [sin(h)], [cos(t)] ) , [h,t], [h_0, t_0], 1 );
[ sin(h_0) + cos(h_0) (h - h_0) + . . . ]
(%o47)/T/ [ ]
[ cos(t_0) - sin(t_0) (t - t_0) + . . . ]
Now that I have the taylor expansion I have, I want this to of the form A[h;t] + b.
coefmatrix( SS, [h,t,1] );
[ sin(h_0) + cos(h_0) (h - h_0) + . . . ]
coefmatrix: improper argument: [ ]
[ cos(t_0) - sin(t_0) (t - t_0) + . . . ]
-- an error. To debug this try: debugmode(true);
This last step gives an error. How can I accomplish what I desire?
After some tinkering, the correct way to do this is:
SS(h,t):= taylor( matrix( [sin(h)], [cos(t)] ) , [h,t], [h_0, t_0], 1 );
q: list_matrix_entries( SS( h,t ) );
A: coefmatrix( q, [h, t] );
b: expand( A . [h,t] - q );
this results in:
(%i6) A: coefmatrix( q, [h,t] );
[ cos(h_0) 0 ]
(%o6) [ ]
[ 0 - sin(t_0) ]
(%i7) b: expand( A . [h,t] - q );
[ h_0 cos(h_0) - sin(h_0) ]
(%o7) [ ]
[ (- t_0 sin(t_0)) - cos(t_0) ]
All in all the function list_matrix_entries was the key.

OLED Test for USBSTK5515 with CCSv6

I am trying to run the test code for the OLED display simulation on the DSP board TMSC320C5515 eZdsp UsbStick, variant "USBSTK5515".
I have included the bsl folder and needed included libraries and header files through the spectrum website. Now the problem is that I am being unable to compile; I am getting the error:
**** Build of configuration Debug for project OLED ****
"G:\\TheDevelopmentKitCodeComposerv6\\ccsv6\\utils\\bin\\gmake" -k all
'Building file: ../main.c'
'Invoking: C5500 Compiler'
"G:/TheDevelopmentKitCodeComposerv6/ccsv6/tools/compiler/c5500_4.4.1/bin/cl55" -v5515 --memory_model=large -g --include_path="C:/Users/SOURINDU/Desktop/usbstk5515_BSL_RevA/usbstk5515_v1/include" --include_path="C:/Users/SOURINDU/Desktop/usbstk1151_Demo_RevA/USBSTK5515_demo/source/USB_Stick_Sample/inc" --include_path="G:/TheDevelopmentKitCodeComposerv6/ccsv6/tools/compiler/c5500_4.4.1/include" --define=c5515 --display_error_number --diag_warning=225 --ptrdiff_size=16 --preproc_with_compile --preproc_dependency="main.pp" "../main.c"
'Finished building: ../main.c'
' '
'Building file: ../usbstk5515bsl/bsl/usbstk5515.c'
'Invoking: C5500 Compiler'
"G:/TheDevelopmentKitCodeComposerv6/ccsv6/tools/compiler/c5500_4.4.1/bin/cl55" -v5515 --memory_model=large -g --include_path="C:/Users/SOURINDU/Desktop/usbstk5515_BSL_RevA/usbstk5515_v1/include" --include_path="C:/Users/SOURINDU/Desktop/usbstk1151_Demo_RevA/USBSTK5515_demo/source/USB_Stick_Sample/inc" --include_path="G:/TheDevelopmentKitCodeComposerv6/ccsv6/tools/compiler/c5500_4.4.1/include" --define=c5515 --display_error_number --diag_warning=225 --ptrdiff_size=16 --preproc_with_compile --preproc_dependency="usbstk5515bsl/bsl/usbstk5515.pp" --obj_directory="usbstk5515bsl/bsl" "../usbstk5515bsl/bsl/usbstk5515.c"
'Finished building: ../usbstk5515bsl/bsl/usbstk5515.c'
' '
'Building file: ../usbstk5515bsl/bsl/usbstk5515_gpio.c'
'Invoking: C5500 Compiler'
"G:/TheDevelopmentKitCodeComposerv6/ccsv6/tools/compiler/c5500_4.4.1/bin/cl55" -v5515 --memory_model=large -g --include_path="C:/Users/SOURINDU/Desktop/usbstk5515_BSL_RevA/usbstk5515_v1/include" --include_path="C:/Users/SOURINDU/Desktop/usbstk1151_Demo_RevA/USBSTK5515_demo/source/USB_Stick_Sample/inc" --include_path="G:/TheDevelopmentKitCodeComposerv6/ccsv6/tools/compiler/c5500_4.4.1/include" --define=c5515 --display_error_number --diag_warning=225 --ptrdiff_size=16 --preproc_with_compile --preproc_dependency="usbstk5515bsl/bsl/usbstk5515_gpio.pp" --obj_directory="usbstk5515bsl/bsl" "../usbstk5515bsl/bsl/usbstk5515_gpio.c"
'Finished building: ../usbstk5515bsl/bsl/usbstk5515_gpio.c'
' '
'Building file: ../usbstk5515bsl/bsl/usbstk5515_i2c.c'
'Invoking: C5500 Compiler'
"G:/TheDevelopmentKitCodeComposerv6/ccsv6/tools/compiler/c5500_4.4.1/bin/cl55" -v5515 --memory_model=large -g --include_path="C:/Users/SOURINDU/Desktop/usbstk5515_BSL_RevA/usbstk5515_v1/include" --include_path="C:/Users/SOURINDU/Desktop/usbstk1151_Demo_RevA/USBSTK5515_demo/source/USB_Stick_Sample/inc" --include_path="G:/TheDevelopmentKitCodeComposerv6/ccsv6/tools/compiler/c5500_4.4.1/include" --define=c5515 --display_error_number --diag_warning=225 --ptrdiff_size=16 --preproc_with_compile --preproc_dependency="usbstk5515bsl/bsl/usbstk5515_i2c.pp" --obj_directory="usbstk5515bsl/bsl" "../usbstk5515bsl/bsl/usbstk5515_i2c.c"
'Finished building: ../usbstk5515bsl/bsl/usbstk5515_i2c.c'
' '
'Building file: ../usbstk5515bsl/bsl/usbstk5515_led.c'
'Invoking: C5500 Compiler'
"G:/TheDevelopmentKitCodeComposerv6/ccsv6/tools/compiler/c5500_4.4.1/bin/cl55" -v5515 --memory_model=large -g --include_path="C:/Users/SOURINDU/Desktop/usbstk5515_BSL_RevA/usbstk5515_v1/include" --include_path="C:/Users/SOURINDU/Desktop/usbstk1151_Demo_RevA/USBSTK5515_demo/source/USB_Stick_Sample/inc" --include_path="G:/TheDevelopmentKitCodeComposerv6/ccsv6/tools/compiler/c5500_4.4.1/include" --define=c5515 --display_error_number --diag_warning=225 --ptrdiff_size=16 --preproc_with_compile --preproc_dependency="usbstk5515bsl/bsl/usbstk5515_led.pp" --obj_directory="usbstk5515bsl/bsl" "../usbstk5515bsl/bsl/usbstk5515_led.c"
'Finished building: ../usbstk5515bsl/bsl/usbstk5515_led.c'
' '
'Building target: OLED.out'
'Invoking: C5500 Linker'
"G:/TheDevelopmentKitCodeComposerv6/ccsv6/tools/compiler/c5500_4.4.1/bin/cl55" -v5515 --memory_model=large -g --define=c5515 --display_error_number --diag_warning=225 --ptrdiff_size=16 -z -m"OLED.map" --stack_size=0x200 --heap_size=0x400 -i"G:/TheDevelopmentKitCodeComposerv6/ccsv6/tools/compiler/c5500_4.4.1/lib" -i"G:/TheDevelopmentKitCodeComposerv6/ccsv6/tools/compiler/c5500_4.4.1/include" --reread_libs --display_error_number --warn_sections --xml_link_info="OLED_linkInfo.xml" --rom_model --sys_stacksize=0x200 -o "OLED.out" "./main.obj" "./usbstk5515bsl/bsl/usbstk5515.obj" "./usbstk5515bsl/bsl/usbstk5515_gpio.obj" "./usbstk5515bsl/bsl/usbstk5515_i2c.obj" "./usbstk5515bsl/bsl/usbstk5515_led.obj" "../lnkx.cmd" "../usbstk5515bsl/usbstk5515bsl.lib" -l"libc.a" -l"rts55x.lib"
<Linking>
undefined first referenced
symbol in file
--------- ----------------
_main G:\TheDevelopmentKitCodeComposerv6\ccsv6\tools\compiler\c5500_4.4.1\lib\rts55x.lib<args_main.obj>
error #10234-D: unresolved symbols remain
error #10010: errors encountered during linking; "OLED.out" not built
>> Compilation failure
gmake: *** [OLED.out] Error 1
gmake: Target `all' not remade because of errors.
**** Build Finished ****
And in the problem window :
Description Resource Path Location Type
#10010 errors encountered during linking; "OLED.out" not built OLED C/C++ Problem
#10234-D unresolved symbols remain OLED C/C++ Problem
unresolved symbol _main, first referenced in G:\TheDevelopmentKitCodeComposerv6\ccsv6\tools\compiler\c5500_4.4.1\lib\rts55x.lib<args_main.obj> OLED C/C++ Problem
My Code as downloaded from spectrum website is
/*
* Copyright 2010 by Spectrum Digital Incorporated.
* All rights reserved. Property of Spectrum Digital Incorporated.
*/
/*
* OSD9616 OLED Test
*
*/
#include "usbstk5515.h"
//#include "usbstk5515_led.h"
#include "usbstk5515_i2c.h"
#include "lcd.h"
#include "usbstk5515_gpio.h"
#define OSD9616_I2C_ADDR 0x3C // OSD9616 I2C address
/* ------------------------------------------------------------------------ *
* *
* Int16 OSD9616_send( Uint16 comdat, Uint16 data ) *
* *
* Sends 2 bytes of data to the OSD9616 *
* *
* ------------------------------------------------------------------------ */
Int16 OSD9616_send( Uint16 comdat, Uint16 data )
{
Uint8 cmd[2];
cmd[0] = comdat & 0x00FF; // Specifies whether data is Command or Data
cmd[1] = data; // Command / Data
return USBSTK5515_I2C_write( OSD9616_I2C_ADDR, cmd, 2 );
}
/* ------------------------------------------------------------------------ *
* *
* Int16 OSD9616_multiSend( Uint16 comdat, Uint16 data ) *
* *
* Sends multiple bytes of data to the OSD9616 *
* *
* ------------------------------------------------------------------------ */
Int16 OSD9616_multiSend( Uint8* data, Uint16 len )
{
Uint16 x;
Uint8 cmd[10];
for(x=0;x<len;x++) // Command / Data
{
cmd[x] = data[x];
}
return USBSTK5515_I2C_write( OSD9616_I2C_ADDR, cmd, len );
}
/* ------------------------------------------------------------------------ *
* *
* Int16 printLetter(Uint16 l1,Uint16 l2,Uint16 l3,Uint16 l4) *
* *
* Send 4 bytes representing a Character *
* *
* ------------------------------------------------------------------------ */
Int16 printLetter(Uint16 l1,Uint16 l2,Uint16 l3,Uint16 l4)
{
OSD9616_send(0x40,l1);
OSD9616_send(0x40,l2);
OSD9616_send(0x40,l3);
OSD9616_send(0x40,l4);
OSD9616_send(0x40,0x00);
return 0;
}
/* ------------------------------------------------------------------------ *
* *
* Int16 oled_test() *
* *
* Testing function for the OSD9616 display *
* *
* ------------------------------------------------------------------------ */
Int16 oled_test()
{
Int16 i, i2c_err;
Uint8 cmd[10]; // For multibyte commands
/* Initialize I2C */
USBSTK5515_I2C_init( );
/* Initialize LCD power */
USBSTK5515_GPIO_setDirection( 12, 1 ); // Output
USBSTK5515_GPIO_setOutput( 12, 1 ); // Enable 13V
/* Initialize OSD9616 display */
i2c_err = OSD9616_send(0x00,0x00); // Set low column address
i2c_err = OSD9616_send(0x00,0x10); // Set high column address
if(i2c_err) // Don't setup display if not connected
return 1;
OSD9616_send(0x00,0x40); // Set start line address
cmd[0] = 0x00 & 0x00FF; // Set contrast control register
cmd[1] = 0x81;
cmd[2] = 0x7f;
USBSTK5515_I2C_write( OSD9616_I2C_ADDR, cmd, 3 );
OSD9616_send(0x00,0xa1); // Set segment re-map 95 to 0
OSD9616_send(0x00,0xa6); // Set normal display
cmd[0] = 0x00 & 0x00FF; // Set multiplex ratio(1 to 16)
cmd[1] = 0xa8;
cmd[2] = 0x0f;
USBSTK5515_I2C_write( OSD9616_I2C_ADDR, cmd, 3 );
OSD9616_send(0x00,0xd3); // Set display offset
OSD9616_send(0x00,0x00); // Not offset
OSD9616_send(0x00,0xd5); // Set display clock divide ratio/oscillator frequency
OSD9616_send(0x00,0xf0); // Set divide ratio
cmd[0] = 0x00 & 0x00FF; // Set pre-charge period
cmd[1] = 0xd9;
cmd[2] = 0x22;
USBSTK5515_I2C_write( OSD9616_I2C_ADDR, cmd, 3 );
cmd[0] = 0x00 & 0x00FF; // Set com pins hardware configuration
cmd[1] = 0xda;
cmd[2] = 0x02;
USBSTK5515_I2C_write( OSD9616_I2C_ADDR, cmd, 3 );
OSD9616_send(0x00,0xdb); // Set vcomh
OSD9616_send(0x00,0x49); // 0.83*vref
cmd[0] = 0x00 & 0x00FF; //--set DC-DC enable
cmd[1] = 0x8d;
cmd[2] = 0x14;
USBSTK5515_I2C_write( OSD9616_I2C_ADDR, cmd, 3 );
OSD9616_send(0x00,0xaf); // Turn on oled panel
/* Fill page 0 */
OSD9616_send(0x00,0x00); // Set low column address
OSD9616_send(0x00,0x10); // Set high column address
OSD9616_send(0x00,0xb0+0); // Set page for page 0 to page 5
for(i=0;i<128;i++)
{
OSD9616_send(0x40,0xff);
}
/* Write to page 0 */
OSD9616_send(0x00,0x00); // Set low column address
OSD9616_send(0x00,0x10); // Set high column address
OSD9616_send(0x00,0xb0+0); // Set page for page 0 to page 5
for(i=0;i<22;i++)
{
OSD9616_send(0x40,0x00); // Spaces
}
printLetter(0x32,0x49,0x49,0x26); // S
printLetter(0x01,0x7F,0x01,0x01); // T
printLetter(0x7F,0x30,0x0E,0x7F); // N
printLetter(0x41,0x49,0x49,0x7F); // E
printLetter(0x7F,0x06,0x06,0x7F); // M
printLetter(0x3F,0x40,0x40,0x3F); // U
printLetter(0x46,0x29,0x19,0x7F); // R
printLetter(0x01,0x7F,0x01,0x01); // T
printLetter(0x32,0x49,0x49,0x26); // S
printLetter(0x7F,0x30,0x0E,0x7F); // N
printLetter(0x00,0x7F,0x00,0x00); // I
for(i=0;i<5;i++)
{
OSD9616_send(0x40,0x00); // Spaces
}
printLetter(0x32,0x49,0x49,0x26); // S
printLetter(0x7C,0x09,0x0A,0x7C); // A
printLetter(0x63,0x1C,0x1C,0x63); // X
printLetter(0x41,0x49,0x49,0x7F); // E
printLetter(0x01,0x7F,0x01,0x01); // T
for(i=0;i<23;i++)
{
OSD9616_send(0x40,0x00); // Spaces
}
/* Fill page 1*/
OSD9616_send(0x00,0x00); // Set low column address
OSD9616_send(0x00,0x10); // Set high column address
OSD9616_send(0x00,0xb0+1); // Set page for page 0 to page 5
for(i=0;i<128;i++)
{
OSD9616_send(0x40,0xff);
}
/* Write to page 1*/
OSD9616_send(0x00,0x00); // Set low column address
OSD9616_send(0x00,0x10); // Set high column address
OSD9616_send(0x00,0xb0+1); // Set page for page 0 to page 5
for(i=0;i<20;i++)
{
OSD9616_send(0x40,0x00);
}
printLetter(0x41,0x22,0x14,0x7F); // K
printLetter(0x22,0x41,0x41,0x3E); // C
printLetter(0x00,0x7F,0x00,0x00); // I
printLetter(0x01,0x7F,0x01,0x01); // T
printLetter(0x32,0x49,0x49,0x26); // S
for(i=0;i<5;i++)
{
OSD9616_send(0x40,0x00); // Spaces
}
printLetter(0x36,0x49,0x49,0x7F); // B
printLetter(0x32,0x49,0x49,0x26); // S
printLetter(0x3F,0x40,0x40,0x3F); // U
for(i=0;i<5;i++)
{
OSD9616_send(0x40,0x00); // Spaces
}
printLetter(0x06,0x09,0x09,0x7F); // P
printLetter(0x32,0x49,0x49,0x26); // S
printLetter(0x3E,0x41,0x41,0x7F); // D
printLetter(0x43,0x4D,0x51,0x61); // Z
printLetter(0x10,0x58,0x58,0x30); // e
for(i=0;i<5;i++)
{
OSD9616_send(0x40,0x00); // Spaces
}
printLetter(0x31,0x49,0x49,0x2F); // 5
printLetter(0x00,0x7F,0x00,0x00); // 1
printLetter(0x31,0x49,0x49,0x2F); // 5
printLetter(0x31,0x49,0x49,0x2F); // 5
printLetter(0x22,0x41,0x41,0x3E); // C
for(i=0;i<23;i++)
{
OSD9616_send(0x40,0x00); // Spaces
}
/* Set vertical and horizontal scrolling */
cmd[0] = 0x00;
cmd[1] = 0x29; // Vertical and Right Horizontal Scroll
cmd[2] = 0x00; // Dummy byte
cmd[3] = 0x00; // Define start page address
cmd[4] = 0x03; // Set time interval between each scroll step
cmd[5] = 0x01; // Define end page address
cmd[6] = 0x01; // Vertical scrolling offset
OSD9616_multiSend( cmd, 7 );
OSD9616_send(0x00,0x2f);
/* Keep first 8 rows from vertical scrolling */
cmd[0] = 0x00;
cmd[1] = 0xa3; // Set Vertical Scroll Area
cmd[2] = 0x08; // Set No. of rows in top fixed area
cmd[3] = 0x08; // Set No. of rows in scroll area
OSD9616_multiSend( cmd, 4 );
return 0;
}
Probably a bit late now, but I think the problem is that you don't have a main function defined to call any of the functions, hence message "unresolved symbol _main".
Not familiar with that particular board, but the example that came with my ezdspc5535 had 2 c files, one of which had a main and examples of how to call the functions in oled_test.c

Resources