Hi HK, I gave up on using the standard functionplotresponse for what I was doing. The attached code works with Geogebra and gnuplot, and uses custom response to evaluate the submissions. The application is a mixer in a superheterodyne receiver. It’s pretty complex, about 700 lines counting comments, but a good bit of that complexity is the computation of values for the harmonics and cross products, then ordering them correctly in their respective arrays.
This may be more than what you want to dig into, but thought I would share it just in case. Best regards, Gene L. Harding, PE Associate Professor of ECET Purdue University 574-520-4190 From: LON-CAPA-users <lon-capa-users-boun...@mail.lon-capa.org> On Behalf Of H. K. Ng Sent: Saturday, June 1, 2019 12:10 PM To: Discussion list for LON-CAPA users <lon-capa-users@mail.lon-capa.org> Subject: [LON-CAPA-users] functionplotresponse problems Good morning, I am looking for examples of functionplotresponse problems (one where a student can resize/drag a vector,..) Let me know if you don't mind sharing the source codes. Thanks. Regards, -hk
<problem> <!-- Author: Gene L. Harding, glhar...@purdue.edu Date: 01 May 2018 --> <!-- Program: PlotMixerOutputHarmsAndXProds_MultPt_InterPlot_PartCredCustResp.problem This program gives the student two random fundamental signal frequencies, then requests a plot of the first three harmonics of each signal, followed by a plot of the cross products for m,n equal 1,2. There are six harmonics in the first plot. The student is awarded 1/6 credit for each vector that is plotted correctly. There are up to eight cross products in the second plot. The student is awarded 1/8 credit for each vector that is plotted correctly. If there are any "0-Hz" vectors, they are to be placed at the origin with magnitude of zero. First order signal vectors (i.e., the fundamentals) are to be plotted with a magnitude of 11 V. Second order signals (i.e., 2nd harmonics and 1,1 cross products) have magnitude 9 V. Third order signals (3rd harmonics, and 1,2 & 2,1 cross products) have magnitude 7 V. Fourth order signals (2,2 cross products) and 0-Hz signals have magnitude 5 V. The program is structured as follows: - Calculate harmonics - Calculate cross products - Sort harmonics by frequency (lowest to highest); place same-freq vectors tip-to-tail largest to smallest - Sort cross products by frequency (lowest to highest); place same-freq vectors tip-to-tail largest to smallest - Calculate parameters for harmonics gnuplot - Calculate parameters for cross products gnuplot - Check harmonics plot submission. Change correct vectors' color to blue; leave incorrect vectors black. Compute harmonics submission score (used during troubleshooting). Determine whether gnuplot "answer" should be displayed (if answer not correct and all tries used). If no submission, set vector locations to initial values and colors to black. - Check cross products plot submission. Change correct vectors' color to blue; leave incorrect vectors black. Compute cross product submission score (used during troubleshooting). Determine whether gnuplot "answer" should be displayed (if answer not correct and all tries used). If no submission, set vector locations to initial values and colors to black. - Set up applets for harmonics Geogebra plot, cross products Geogebra plot, then call window load function. - Javascript that does the following: -- Sets up the GGBOnInit function to update Geogebra harmonic and cross product plot values with Perl values and "listen" for changes. -- Read updated Geogebra harmonics plot values and pass them to LON-CAPA harmonics submission -- Read updated Geogebra cross product plot values and pass them to LON-CAPA cross products submission - Part "a": -- Custom response block to evaluate harmonics submission, calculate score, and pass to LON-CAPA. -- Invisible table contains interactive Geogebra harmonics plot on left, gnuplot answer on right. gnuplot is only displayed if answer is not completely correct after all tries used. - Part "b": -- Custom response block to evaluate cross products submission, calculate score, and pass to LON-CAPA. -- Invisible table contains interactive Geogebra cross products plot on left, gnuplot answer on right. gnuplot is only displayed if answer is not completely correct after all tries used. --> <!-- maxtries parameter format --> <parameter name="maxtries" id="23" type="int_pos" default="3" description="Maximum Number of Tries" /> <!-- Needed to give student multiple attempts for custom response problem --> <parameter name="retrypartial" id="24" type="string_yesno" default="yes" description="Partially correct is answerable" /> <parameter name="problemstatus" id="25" type="string_problemstatus" default="yes" description="Show Problem Status" /> <script type="loncapa/perl"> $num_harms = 3; # Number of harmonics for signals a and b $xprod_mn = 2; # Cross product m & n values --> m**2 cross products ########################################### Calculate harmonics ################################################# #$fa[1] = 4; $A[1] = 11; # Fundamental freq in MHz and magn in V of signal a; fixed values used in development $fa[1] = random(3,5,1); $A[1] = 11; # Fundamental freq in MHz and magn in V of signal a for ($i=2; $i<=$num_harms; $i++) { $fa[$i] = $i*$fa[1]; $A[$i] = &max(11-2*($i-1),1); } # Signal a harmonics #$fb[1] = 8; $B[1] = 11; # Fundamental freq in MHz and magn in V of signal b; fixed values used in development $fb[1] = &random(6,10,2); $B[1] = 11; # Fundamental freq in MHz and magn in V of signal b for ($i=2; $i<=$num_harms; $i++) { $fb[$i] = $i*$fb[1]; $B[$i] = &max(11-2*($i-1),1); } # Signal b harmonics ################################################################################################################# ######################################## Calculate cross products ############################################### $cp_count = 0; # Element to track # x-prod's array size for ($i=1; $i<=$xprod_mn; $i++) # Cycle through first column {for ($j=1; $j<=$xprod_mn; $j++) # Cycle through second column: 1 per sum freq, 1 per diff freq {$cp_count++; $cp[$cp_count] = $fa[$i]+$fb[$j]; # Add frequency sum element (lower case) to frequency array $CP[$cp_count] = &max(13-2*($i+$j),1); # Add magnitude element (upper case) to magnitude array if (&abs($fa[$i]-$fb[$j]) != 0) # If frequency diff element <> 0, add this element to array {$cp_count++; $cp[$cp_count] = &abs($fa[$i]-$fb[$j]); # Add frequency diff element (lower case) to frequency array $CP[$cp_count] = &max(13-2*($i+$j),1); # Add magnitude element (upper case) to frequency array } } } ################################################################################################################# ####################################### Set up harmonic plot arrays ############################################# for ($i=1; $i<=$num_harms; $i++) {$f[$i-1] = $fa[$i]; $mag[$i-1] = $A[$i];} # Put signal a harmonics in lower part of frequency array for ($i=1; $i<=$num_harms; $i++) {$f[$i+$num_harms-1] = $fb[$i]; $mag[$i+$num_harms-1] = $B[$i];} # Put signal b harmonics in upper part of frequency array for ($i=$num_harms*2-2; $i>=0; $i--) # Bubble sort frequency (f) and magnitude (mag) arrays { for ($j=0; $j<=$i; $j++) # Inner loop, swaps elements one at a time if out of order { if ( $f[$j] > $f[$j+1] ) # If elements out of order, swap elements { $temp=$f[$j]; $f[$j] =$f[$j+1]; $f[$j+1]=$temp; # Swap frequencies $temp=$mag[$j]; $mag[$j]=$mag[$j+1]; $mag[$j+1]=$temp; # Swap magnitudes } } } do { # Order vectors at same freq from largest to smallest $swap = 0; # Initialize to false for ($i=0; $i<=$num_harms*2-2; $i++) { if (($f[$i]==$f[$i+1]) && ($mag[$i] < $mag[$i+1])) # If same frequency and second vector is larger --> swap { $temp=$f[$i]; $f[$i] =$f[$i+1]; $f[$i+1]=$temp; # Swap frequencies $temp=$mag[$i]; $mag[$i]=$mag[$i+1]; $mag[$i+1]=$temp; # Swap magnitudes $swap = 1; # Did a swap this loop, so may not be done } } } while ($swap); # Stop looping once no more swaps (array in order) for ($i=0; $i<=$num_harms*2-1; $i++) { $zeros[$i]=0; } # Set up plot array of zeros (to be used for deltaX values in plot) @tails = @zeros; # Initialize tail of each vector to zero for ($i=1; $i<=$num_harms*2-1; $i++) { if ( $f[$i]==$f[$i-1] ) # If frequency matches previous vector's frequency then... { $tails[$i] = $tails[$i-1]+$mag[$i-1]; } # ...place tail of this vector at tip of previous vector. } for ($i=0; $i<=$num_harms*2-1; $i++) { $tip[$i] = $tails[$i]+$mag[$i];} # Set tip vertical location for each vector # NOTE: gnuplot needs tail(x,y) and (delta_x,delta_y) values; # Geogebra needs tail(x,y) and tip(x,y) values. ################################################################################################################# ####################################### Set up cross product plot arrays ######################################## for ($i=1; $i<=$cp_count; $i++) {$fcp[$i-1] = $cp[$i]; $magcp[$i-1] = $CP[$i];} # Put cross-products in plot freq & mag arrays for ($i=$cp_count-1; $i>=0; $i--) # Bubble sort frequency (f) and magnitude (mag) arrays { for ($j=0; $j<=$i-1; $j++) # Inner loop, swaps elements one at a time if out of order { if ( $fcp[$j] > $fcp[$j+1] ) # If elements out of order, swap elements { $temp=$fcp[$j]; $fcp[$j] =$fcp[$j+1]; $fcp[$j+1]=$temp; # Swap frequencies $temp=$magcp[$j]; $magcp[$j]=$magcp[$j+1]; $magcp[$j+1]=$temp; # Swap magnitudes } } } do { # Order vectors at same freq from largest to smallest $swap = 0; # Initialize to false for ($i=0; $i<=$cp_count-1; $i++) { if (($fcp[$i]==$fcp[$i+1]) && ($magcp[$i] < $magcp[$i+1])) # If same frequency and second vector is larger --> swap { $temp=$fcp[$i]; $fcp[$i] =$fcp[$i+1]; $fcp[$i+1]=$temp; # Swap frequencies $temp=$magcp[$i]; $magcp[$i]=$magcp[$i+1]; $magcp[$i+1]=$temp; # Swap magnitudes $swap = 1; # Did a swap this loop, so may not be done, leave true } } } while ($swap); # Stop looping once no more swaps (array in order) for ($i=0; $i<=$cp_count-1; $i++) { $zeroscp[$i]=0; } # Set up plot array of zeros (to be used for deltaX values in plot) @tailscp = @zeroscp; # Initialize tail of each vector to zero for ($i=1; $i<=$cp_count; $i++) { if ( $fcp[$i]==$fcp[$i-1] ) # If frequency matches previous vector's frequency then... { $tailscp[$i] = $tailscp[$i-1]+$magcp[$i-1]; } # ...place tail of this vector at tip of previous vector. } for ($i=0; $i<=$cp_count-1; $i++) { $tipcp[$i] = $tailscp[$i]+$magcp[$i];} # Set tip vertical location for each vector for ($i=4; $i<=7; $i++) { if ($fcp[$i]=="") { $fcp[$i]=0; $tailscp[$i]=0; $tipcp[$i]=5; $zeroscp[$i]=0; $magcp[$i]=5;} # Unused vectors go to origin with magnitude of 5 } # NOTE: gnuplot needs tail(x,y) and (delta_x,delta_y) values; # Geogebra needs tail(x,y) and tip(x,y) values. ################################################################################################################# ##################################### Calculate harmonics gnuplot parameters #################################### $x_min = 0; # x axis starts at 0 $x_max = &max(40,&max(@f)+2); # x axis ends at max freq + 2 MHz $xtic_incr = &max(2,&floor($x_max/15)); $xtic_stop = $x_max; # x tic marks all the way across axis $y_min = 0; # y axis starts at 0 $y_max = &max(30,(&max(@tails)+&max(@mag))); # y axis ends at tip of tallest stack of vectors $ytic_stop = $y_max; $arwhd = &max(@f)/25; # Size arrowheads in proportion to x axis ################################################################################################################# ################################# Calculate cross products gnuplot parameters ################################### $x_min_cp = 0; # x axis starts at 0 $x_max_cp = &max(40,&max(@fcp)+2); # x axis ends at max freq + 2 MHz $xtic_incr_cp = &max(2,&floor($x_max_cp/15)); $xtic_stop_cp = $x_max_cp; # x tic marks all the way across axis $y_min_cp = 0; # y axis starts at 0 $y_max_cp = &max(30,&max(@tailscp)+&max(@magcp)); # y axis ends at tip of tallest stack of vectors $ytic_stop_cp = $y_max; $arwhd_cp = &max(@fcp)/25; # Size arrowheads in proportion to x axis ################################################################################################################# ############## Set up Geogebra so submitted harmonic answers are not lost on re-initialization ################## $temp = &submission("a","11"); # If there has been a submission, update x & y vector perl values, check each vector for accuracy, # set vector color to blue if correct or black if wrong, update each score part, recompute # total score, and determine whether correct answer needs to be displayed. # If no submission, initialize locations and colors. if ($temp ne '') { ($v1_tailx, $v1_taily, $v1_tipx, $v1_tipy, # Update vector v1 values $v2_tailx, $v2_taily, $v2_tipx, $v2_tipy, # Update vector v2 values $v3_tailx, $v3_taily, $v3_tipx, $v3_tipy, # Update vector v3 values $v4_tailx, $v4_taily, $v4_tipx, $v4_tipy, # Update vector v4 values $v5_tailx, $v5_taily, $v5_tipx, $v5_tipy, # Update vector v5 values $v6_tailx, $v6_taily, $v6_tipx, $v6_tipy) # Update vector v6 values = split(',',&submission("a","11")); if ($v1_tailx==$f[0] && $v1_taily==$tails[0] && $v1_tipx==$f[0] && $v1_tipy==$tip[0]) { $v1_color="Blue"; $v1part=1/6;} # If correct change color to blue, update part 1 score else { $v1_color="Black"; $v1part=0;} # If wrong keep color black, part 1 score zero if ($v2_tailx==$f[1] && $v2_taily==$tails[1] && $v2_tipx==$f[1] && $v2_tipy==$tip[1]) { $v2_color="Blue"; $v2part=1/6;} # If correct change color to blue, update part 2 score else { $v2_color="Black"; $v2part=0;} # If wrong keep color black, part 2 score zero if ($v3_tailx==$f[2] && $v3_taily==$tails[2] && $v3_tipx==$f[2] && $v3_tipy==$tip[2]) { $v3_color="Blue"; $v3part=1/6;} # If correct change color to blue, update part 3 score else { $v3_color="Black"; $v3part=0;} # If wrong keep color black, part 3 score zero if ($v4_tailx==$f[3] && $v4_taily==$tails[3] && $v4_tipx==$f[3] && $v4_tipy==$tip[3]) { $v4_color="Blue"; $v4part=1/6;} # If correct change color to blue, update part 4 score else { $v4_color="Black"; $v4part=0;} # If wrong keep color black, part 4 score zero if ($v5_tailx==$f[4] && $v5_taily==$tails[4] && $v5_tipx==$f[4] && $v5_tipy==$tip[4]) { $v5_color="Blue"; $v5part=1/6;} # If correct change color to blue, update part 5 score else { $v5_color="Black"; $v5part=0;} # If wrong keep color black, part 5 score zero if ($v6_tailx==$f[5] && $v6_taily==$tails[5] && $v6_tipx==$f[5] && $v6_tipy==$tip[5]) { $v6_color="Blue"; $v6part=1/6;} # If correct change color to blue, update part 6 score else { $v6_color="Black"; $v6part=0;} # If wrong keep color black, part 6 score zero # The next three variables are calculated to determine whether to show the harmonics plot answer $total_score = $v1part+$v2part+$v3part+$v4part+$v5part+$v6part; # Update total score $maxtries = ¶meter_setting("maxtries","a"); $tries = &stored_data("tries","a"); # Show harmonics answer using gnuplot if tries used up and answer still wrong * if ($total_score eq 1 || $tries<$maxtries) # If correct or tries left, ### QUESTION: Why does it think $total_score and/or 1 is a string? "==" did not work... ### { $ShowHarmPlot=0; } # set to 0 so conditional block does not execute else { $ShowHarmPlot=1; } # If wrong & maxtries reached, set to 1 so conditional block executes } else # If no submission, set vectors to initial location and color values { # Initial harmonic vector locations $v1_tailx = 40; $v1_taily = 4; $v1_tipx = 43; $v1_tipy = 4; $v1_color = "Black"; # Set initial vector color to black. $v2_tailx = 40; $v2_taily = 7; $v2_tipx = 43; $v2_tipy = 7; $v2_color = "Black"; # Set initial vector color to black. $v3_tailx = 40; $v3_taily = 10; $v3_tipx = 43; $v3_tipy = 10; $v3_color = "Black"; # Set initial vector color to black. $v4_tailx = 40; $v4_taily = 13; $v4_tipx = 43; $v4_tipy = 13; $v4_color = "Black"; # Set initial vector color to black. $v5_tailx = 40; $v5_taily = 16; $v5_tipx = 43; $v5_tipy = 16; $v5_color = "Black"; # Set initial vector color to black. $v6_tailx = 40; $v6_taily = 19; $v6_tipx = 43; $v6_tipy = 19; $v6_color = "Black"; # Set initial vector color to black. } ################################################################################################################# ############ Set up Geogebra so submitted cross-product answers are not lost on re-initialization ############### $temp2 = &submission("b","22"); # Read part 22 submission (v1cp tail x value) into temp variable # If there has been a submission, update x & y vector perl values, check each vector for accuracy, # set vector color to blue if correct or black if wrong, update each score part, recompute # total score, and determine whether correct answer needs to be displayed. # If no submission, initialize locations and colors. if ($temp2 ne '') # If something submitted then read set all submission values { ($v1cp_tailx, $v1cp_taily, $v1cp_tipx, $v1cp_tipy, # Update vector v1 values $v2cp_tailx, $v2cp_taily, $v2cp_tipx, $v2cp_tipy, # Update vector v2 values $v3cp_tailx, $v3cp_taily, $v3cp_tipx, $v3cp_tipy, # Update vector v3 values $v4cp_tailx, $v4cp_taily, $v4cp_tipx, $v4cp_tipy, # Update vector v4 values $v5cp_tailx, $v5cp_taily, $v5cp_tipx, $v5cp_tipy, # Update vector v5 values $v6cp_tailx, $v6cp_taily, $v6cp_tipx, $v6cp_tipy, # Update vector v6 values $v7cp_tailx, $v7cp_taily, $v7cp_tipx, $v7cp_tipy, # Update vector v7 values $v8cp_tailx, $v8cp_taily, $v8cp_tipx, $v8cp_tipy) # Update vector v8 values = split(',',&submission("b","22")); if ($v1cp_tailx==$fcp[0] && $v1cp_taily==$tailscp[0] && $v1cp_tipx==$fcp[0] && $v1cp_tipy==$tipcp[0]) { $v1cp_color="Blue"; $v1cppart=1/8;} # If correct change color to blue, update part 1 score else { $v1cp_color="Black"; $v1cppart=0;} # If wrong keep color black, part 1 score zero if ($v2cp_tailx==$fcp[1] && $v2cp_taily==$tailscp[1] && $v2cp_tipx==$fcp[1] && $v2cp_tipy==$tipcp[1]) { $v2cp_color="Blue"; $v2cppart=1/8;} # If correct change color to blue, update part 2 score else { $v2cp_color="Black"; $v2cppart=0;} # If wrong keep color black, part 2 score zero if ($v3cp_tailx==$fcp[2] && $v3cp_taily==$tailscp[2] && $v3cp_tipx==$fcp[2] && $v3cp_tipy==$tipcp[2]) { $v3cp_color="Blue"; $v3cppart=1/8;} # If correct change color to blue, update part 3 score else { $v3cp_color="Black"; $v3cppart=0;} # If wrong keep color black, part 3 score zero if ($v4cp_tailx==$fcp[3] && $v4cp_taily==$tailscp[3] && $v4cp_tipx==$fcp[3] && $v4cp_tipy==$tipcp[3]) { $v4cp_color="Blue"; $v4cppart=1/8;} # If correct change color to blue, update part 4 score else { $v4cp_color="Black"; $v4cppart=0;} # If wrong keep color black, part 4 score zero if ($v5cp_tailx==$fcp[4] && $v5cp_taily==$tailscp[4] && $v5cp_tipx==$fcp[4] && $v5cp_tipy==$tipcp[4]) { $v5cp_color="Blue"; $v5cppart=1/8;} # If correct change color to blue, update part 5 score else { $v5cp_color="Black"; $v5cppart=0;} # If wrong keep color black, part 5 score zero if ($v6cp_tailx==$fcp[5] && $v6cp_taily==$tailscp[5] && $v6cp_tipx==$fcp[5] && $v6cp_tipy==$tipcp[5]) { $v6cp_color="Blue"; $v6cppart=1/8;} # If correct change color to blue, update part 6 score else { $v6cp_color="Black"; $v6cppart=0;} # If wrong keep color black, part 6 score zero if ($v7cp_tailx==$fcp[6] && $v7cp_taily==$tailscp[6] && $v7cp_tipx==$fcp[6] && $v7cp_tipy==$tipcp[6]) { $v7cp_color="Blue"; $v7cppart=1/8;} # If correct change color to blue, update part 7 score else { $v7cp_color="Black"; $v7cppart=0;} # If wrong keep color black, part 7 score zero if ($v8cp_tailx==$fcp[7] && $v8cp_taily==$tailscp[7] && $v8cp_tipx==$fcp[7] && $v8cp_tipy==$tipcp[7]) { $v8cp_color="Blue"; $v8cppart=1/8;} # If correct change color to blue, update part 8 score else { $v8cp_color="Black"; $v8cppart=0;} # If wrong keep color black, part 8 score zero $total_cpscore = $v1cppart+$v2cppart+$v3cppart+$v4cppart+$v5cppart+$v6cppart+$v7cppart+$v8cppart; $maxtriesb = ¶meter_setting("maxtries","b"); $triesb = &stored_data("tries","b"); # Show cross-products answer using gnuplot if tries used up and answer still wrong * if ($total_cpscore eq 1 || $triesb<$maxtriesb) # If correct or tries left, ### QUESTION: Why does it think $total_cpscore and/or 1 is a string? "==" did not work... ### { $ShowXProdPlot=0; } # set to 0 so conditional block does not execute else { $ShowXProdPlot=1; } # If wrong & maxtries reached, set to 1 so conditional block executes } else # If no submission, set vectors to initial location and color values { # Initial cross-product vector locations and colors $v1cp_tailx = 40; $v1cp_taily = 4; $v1cp_tipx = 43; $v1cp_tipy = 4; $v1cp_color = "Black"; # Set initial vector color to black. $v2cp_tailx = 40; $v2cp_taily = 7; $v2cp_tipx = 43; $v2cp_tipy = 7; $v2cp_color = "Black"; # Set initial vector color to black. $v3cp_tailx = 40; $v3cp_taily = 10; $v3cp_tipx = 43; $v3cp_tipy = 10; $v3cp_color = "Black"; # Set initial vector color to black. $v4cp_tailx = 40; $v4cp_taily = 13; $v4cp_tipx = 43; $v4cp_tipy = 13; $v4cp_color = "Black"; # Set initial vector color to black. $v5cp_tailx = 40; $v5cp_taily = 16; $v5cp_tipx = 43; $v5cp_tipy = 16; $v5cp_color = "Black"; # Set initial vector color to black. $v6cp_tailx = 40; $v6cp_taily = 19; $v6cp_tipx = 43; $v6cp_tipy = 19; $v6cp_color = "Black"; # Set initial vector color to black. $v7cp_tailx = 40; $v7cp_taily = 22; $v7cp_tipx = 43; $v7cp_tipy = 22; $v7cp_color = "Black"; # Set initial vector color to black. $v8cp_tailx = 40; $v8cp_taily = 25; $v8cp_tipx = 43; $v8cp_tipy = 25; $v8cp_color = "Black"; # Set initial vector color to black. } ################################################################################################################# </script> <!-- This command includes the javascript library. --> <script src="/geogebra/deployggb.js" type="text/javascript"> </script> <!-- { filename:"/res/purdue/ecet_purdue/Topics/RF/Mixing/SixVectors_FreqSpectrum_material-H9ecmkmh.zip", --> <script type="text/javascript"> var applet = new GGBApplet( // Harmonics applet { id:"harmonics", filename:"/res/purdue/ecet_purdue/Topics/Libraries/SixVectors_FreqSpectrum_XAxisMHz_YAxisV_material-umgpsv5X.zip", borderColor:"#FFFFFF", showToolBar:"true", width:"550",height:"550", showToolBar:"true", rounding:"0", showMenuBar:"false", showAlgebraInput:"false", allowStyleBar:"false", showResetIcon:"false", enableLabelDrags:"false", enableShiftDragZoom:"true", enableRightClick:"false", showToolBarHelp:"true", errorDialogsActive:true, useBrowserForJS:true, language:"en", isPreloader:false, screenshotGenerator:false, preventFocus:true, showSplash:false, scale:"1", fixApplet:false, prerelease:false, playButtonAutoDecide:true, playButton:false, canary:false }); var applet2 = new GGBApplet( // Cross products applet { id:"crossprods", filename:"/res/purdue/ecet_purdue/Topics/Libraries/Eight-vector_Xprod_SpectrumPlot_XaxisMHz_YaxisV_material-dUA5ZHhR.zip", borderColor:"#FFFFFF", showToolBar:"true", width:"550",height:"550", showToolBar:"true", showMenuBar:"false", showAlgebraInput:"false", allowStyleBar:"false", showResetIcon:"false", enableLabelDrags:"false", enableShiftDragZoom:"true", enableRightClick:"false", showToolBarHelp:"true", errorDialogsActive:true, useBrowserForJS:true, language:"en", isPreloader:false, screenshotGenerator:false, preventFocus:true, showSplash:false, scale:"1", fixApplet:false, prerelease:false, playButtonAutoDecide:true, playButton:false, canary:false }); window.onload = function() { applet.inject('harmonicsplot_applet_container', 'preferHTML5'); // 1st part of name corresponds to var name above ("applet") applet2.inject('applet_container2', 'preferHTML5'); } </script> <script type="text/javascript"> function ggbOnInit(applet_id) // This function executes when applet is first called/initialized. { // This block of code is for the first Geogebra plot, harmonics if (applet_id == "harmonics") { // In each of these commands, the middle name (harmonics) corresponds to the applet id above document.harmonics.evalCommand("SetColor[v1,$v1_color]"); // Update v1 color: black=wrong, blue=correct document.harmonics.evalCommand("Tail1=($v1_tailx,$v1_taily)"); // Update Geogebra point "Tail1" with perl values document.harmonics.evalCommand("Tip1=($v1_tipx,$v1_tipy)"); // Update Geogebra point "Tip1" with perl values document.harmonics.evalCommand("SetColor[v2,$v2_color]"); // Update v2 color: black=wrong, blue=correct document.harmonics.evalCommand("Tail2=($v2_tailx,$v2_taily)"); // Update Geogebra point "Tail2" with perl values document.harmonics.evalCommand("Tip2=($v2_tipx,$v2_tipy)"); // Update Geogebra point "Tip2" with perl values document.harmonics.evalCommand("SetColor[v3,$v3_color]"); // Update v3 color: black=wrong, blue=correct document.harmonics.evalCommand("Tail3=($v3_tailx,$v3_taily)"); // Update Geogebra point "Tail3" with perl values document.harmonics.evalCommand("Tip3=($v3_tipx,$v3_tipy)"); // Update Geogebra point "Tip3" with perl values document.harmonics.evalCommand("SetColor[v4,$v4_color]"); // Update v4 color: black=wrong, blue=correct document.harmonics.evalCommand("Tail4=($v4_tailx,$v4_taily)"); // Update Geogebra point "Tail4" with perl values document.harmonics.evalCommand("Tip4=($v4_tipx,$v4_tipy)"); // Update Geogebra point "Tip4" with perl values document.harmonics.evalCommand("SetColor[v5,$v5_color]"); // Update v5 color: black=wrong, blue=correct document.harmonics.evalCommand("Tail5=($v5_tailx,$v5_taily)"); // Update Geogebra point "Tail5" with perl values document.harmonics.evalCommand("Tip5=($v5_tipx,$v5_tipy)"); // Update Geogebra point "Tip5" with perl values document.harmonics.evalCommand("SetColor[v6,$v6_color]"); // Update v6 color: black=wrong, blue=correct document.harmonics.evalCommand("Tail6=($v6_tailx,$v6_taily)"); // Update Geogebra point "Tail6" with perl values document.harmonics.evalCommand("Tip6=($v6_tipx,$v6_tipy)"); // Update Geogebra point "Tip6" with perl values document.harmonics.registerUpdateListener("setValues"); // Listens for any change in app. } // This block of code is for the second Geogebra plot, cross products if (applet_id == "crossprods") { // In each of these commands, the middle name (crossprods) corresponds to the applet id above document.crossprods.evalCommand("SetColor[v1cp,$v1cp_color]"); // Update v1cp color: black=wrong, blue=correct document.crossprods.evalCommand("Tail1cp=($v1cp_tailx,$v1cp_taily)"); // Update Geogebra point "Tail1cp" with perl values document.crossprods.evalCommand("Tip1cp=($v1cp_tipx,$v1cp_tipy)"); // Update Geogebra point "Tip1cp" with perl values document.crossprods.evalCommand("SetColor[v2cp,$v2cp_color]"); // Update v2cp color: black=wrong, blue=correct document.crossprods.evalCommand("Tail2cp=($v2cp_tailx,$v2cp_taily)"); // Update Geogebra point "Tail2cp" with perl values document.crossprods.evalCommand("Tip2cp=($v2cp_tipx,$v2cp_tipy)"); // Update Geogebra point "Tip2cp" with perl values document.crossprods.evalCommand("SetColor[v3cp,$v3cp_color]"); // Update v3cp color: black=wrong, blue=correct document.crossprods.evalCommand("Tail3cp=($v3cp_tailx,$v3cp_taily)"); // Update Geogebra point "Tail3cp" with perl values document.crossprods.evalCommand("Tip3cp=($v3cp_tipx,$v3cp_tipy)"); // Update Geogebra point "Tip3cp" with perl values document.crossprods.evalCommand("SetColor[v4cp,$v4cp_color]"); // Update v4cp color: black=wrong, blue=correct document.crossprods.evalCommand("Tail4cp=($v4cp_tailx,$v4cp_taily)"); // Update Geogebra point "Tail4cp" with perl values document.crossprods.evalCommand("Tip4cp=($v4cp_tipx,$v4cp_tipy)"); // Update Geogebra point "Tip4cp" with perl values document.crossprods.evalCommand("SetColor[v5cp,$v5cp_color]"); // Update v5cp color: black=wrong, blue=correct document.crossprods.evalCommand("Tail5cp=($v5cp_tailx,$v5cp_taily)"); // Update Geogebra point "Tail5cp" with perl values document.crossprods.evalCommand("Tip5cp=($v5cp_tipx,$v5cp_tipy)"); // Update Geogebra point "Tip5cp" with perl values document.crossprods.evalCommand("SetColor[v6cp,$v6cp_color]"); // Update v6cp color: black=wrong, blue=correct document.crossprods.evalCommand("Tail6cp=($v6cp_tailx,$v6cp_taily)"); // Update Geogebra point "Tail6cp" with perl values document.crossprods.evalCommand("Tip6cp=($v6cp_tipx,$v6cp_tipy)"); // Update Geogebra point "Tip6cp" with perl values document.crossprods.evalCommand("SetColor[v7cp,$v7cp_color]"); // Update v7cp color: black=wrong, blue=correct document.crossprods.evalCommand("Tail7cp=($v7cp_tailx,$v7cp_taily)"); // Update Geogebra point "Tail7cp" with perl values document.crossprods.evalCommand("Tip7cp=($v7cp_tipx,$v7cp_tipy)"); // Update Geogebra point "Tip7cp" with perl values document.crossprods.evalCommand("SetColor[v8cp,$v8cp_color]"); // Update v8cp color: black=wrong, blue=correct document.crossprods.evalCommand("Tail8cp=($v8cp_tailx,$v8cp_taily)"); // Update Geogebra point "Tail8cp" with perl values document.crossprods.evalCommand("Tip8cp=($v8cp_tipx,$v8cp_tipy)"); // Update Geogebra point "Tip8cp" with perl values document.crossprods.registerUpdateListener("setValues2"); // Listens for any change in app. } } function setValues(){ // Get location of each harmonic vector's tip & tail. // Vector v1 var ax = Math.round(document.harmonics.getXcoord("Tail1")); var ay = Math.round(document.harmonics.getYcoord("Tail1")); var bx = Math.round(document.harmonics.getXcoord("Tip1")); var by = Math.round(document.harmonics.getYcoord("Tip1")); // Vector v2 var cx = Math.round(document.harmonics.getXcoord("Tail2")); var cy = Math.round(document.harmonics.getYcoord("Tail2")); var dx = Math.round(document.harmonics.getXcoord("Tip2")); var dy = Math.round(document.harmonics.getYcoord("Tip2")); // Vector v3 var ex = Math.round(document.harmonics.getXcoord("Tail3")); var ey = Math.round(document.harmonics.getYcoord("Tail3")); var fx = Math.round(document.harmonics.getXcoord("Tip3")); var fy = Math.round(document.harmonics.getYcoord("Tip3")); // Vector v4 var gx = Math.round(document.harmonics.getXcoord("Tail4")); var gy = Math.round(document.harmonics.getYcoord("Tail4")); var hx = Math.round(document.harmonics.getXcoord("Tip4")); var hy = Math.round(document.harmonics.getYcoord("Tip4")); // Vector v5 var ix = Math.round(document.harmonics.getXcoord("Tail5")); var iy = Math.round(document.harmonics.getYcoord("Tail5")); var jx = Math.round(document.harmonics.getXcoord("Tip5")); var jy = Math.round(document.harmonics.getYcoord("Tip5")); // Vector v6 var kx = Math.round(document.harmonics.getXcoord("Tail6")); var ky = Math.round(document.harmonics.getYcoord("Tail6")); var lx = Math.round(document.harmonics.getXcoord("Tip6")); var ly = Math.round(document.harmonics.getYcoord("Tip6")); // Place harmonic tip & tail info into corresponding submission elements. document.lonhomework.elements["HWVAL_11"].value = [ax,ay,bx,by,cx,cy,dx,dy,ex,ey,fx,fy,gx,gy,hx,hy,ix,iy,jx,jy,kx,ky,lx,ly]; } function setValues2(){ // Get location of each cross-product vector's tip & tail. // Vector v1cp var aax = Math.round(document.crossprods.getXcoord("Tail1cp")); var aay = Math.round(document.crossprods.getYcoord("Tail1cp")); var bbx = Math.round(document.crossprods.getXcoord("Tip1cp")); var bby = Math.round(document.crossprods.getYcoord("Tip1cp")); // Vector v2cp var ccx = Math.round(document.crossprods.getXcoord("Tail2cp")); var ccy = Math.round(document.crossprods.getYcoord("Tail2cp")); var ddx = Math.round(document.crossprods.getXcoord("Tip2cp")); var ddy = Math.round(document.crossprods.getYcoord("Tip2cp")); // Vector v3cp var eex = Math.round(document.crossprods.getXcoord("Tail3cp")); var eey = Math.round(document.crossprods.getYcoord("Tail3cp")); var ffx = Math.round(document.crossprods.getXcoord("Tip3cp")); var ffy = Math.round(document.crossprods.getYcoord("Tip3cp")); // Vector v4cp var ggx = Math.round(document.crossprods.getXcoord("Tail4cp")); var ggy = Math.round(document.crossprods.getYcoord("Tail4cp")); var hhx = Math.round(document.crossprods.getXcoord("Tip4cp")); var hhy = Math.round(document.crossprods.getYcoord("Tip4cp")); // Vector v5cp var iix = Math.round(document.crossprods.getXcoord("Tail5cp")); var iiy = Math.round(document.crossprods.getYcoord("Tail5cp")); var jjx = Math.round(document.crossprods.getXcoord("Tip5cp")); var jjy = Math.round(document.crossprods.getYcoord("Tip5cp")); // Vector v6cp var kkx = Math.round(document.crossprods.getXcoord("Tail6cp")); var kky = Math.round(document.crossprods.getYcoord("Tail6cp")); var llx = Math.round(document.crossprods.getXcoord("Tip6cp")); var lly = Math.round(document.crossprods.getYcoord("Tip6cp")); // Vector v7cp var mmx = Math.round(document.crossprods.getXcoord("Tail7cp")); var mmy = Math.round(document.crossprods.getYcoord("Tail7cp")); var nnx = Math.round(document.crossprods.getXcoord("Tip7cp")); var nny = Math.round(document.crossprods.getYcoord("Tip7cp")); // Vector v8cp var oox = Math.round(document.crossprods.getXcoord("Tail8cp")); var ooy = Math.round(document.crossprods.getYcoord("Tail8cp")); var ppx = Math.round(document.crossprods.getXcoord("Tip8cp")); var ppy = Math.round(document.crossprods.getYcoord("Tip8cp")); // Place cross-product tip & tail info into corresponding submission elements. document.lonhomework.elements["HWVAL_22"].value = [aax,aay,bbx,bby,ccx,ccy,ddx,ddy,eex,eey,ffx,ffy,ggx,ggy,hhx,hhy, iix,iiy,jjx,jjy,kkx,kky,llx,lly,mmx,mmy,nnx,nny,oox,ooy,ppx,ppy]; } </script> <startouttext /> Create the following plots of the output spectrum for a non-linear mixer <br /> with two signal inputs: one at $fa[1] MHz and the other at $fb[1] MHz. <br /> NOTE: First order signals are 11 V, second order signals are 9 V, third <br /> order signals are 7 V, etc. <br /><br /> <endouttext /> <part id="a"> <startouttext />¤tpart. Plot the first three harmonics of each signal, working from lowest <br /> to highest frequency. If multiple harmonics occur at the same frequency, <br /> plot them tip to tail from largest to smallest. <br /><br /> <endouttext /> <customresponse id="11"> <answer type="loncapa/perl"> # These submission variables appear to be local to this (part or custom response) only. ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r,$s,$t,$u,$v,$w,$x) = split(',',$submission); # Variables such as $f[0] are global when used in conditional expressions, but # assignments appear to only work for local variables. if ($a==$f[0] && $b==$tails[0] && $c==$f[0] && $d==$tip[0]) { $v1part=1/6;} # If correct, update part 1 score else { $v1part=0;} # If wrong keep part 1 score zero if ($e==$f[1] && $f==$tails[1] && $g==$f[1] && $h==$tip[1]) { $v2part=1/6;} # If correct, update part 2 score else { $v2part=0;} # If wrong keep part 2 score zero if ($i==$f[2] && $j==$tails[2] && $k==$f[2] && $l==$tip[2]) { $v3part=1/6;} # If correct, update part 3 score else { $v3part=0;} # If wrong keep part 3 score zero if ($m==$f[3] && $n==$tails[3] && $o==$f[3] && $p==$tip[3]) { $v4part=1/6;} # If correct, update part 4 score else { $v4part=0;} # If wrong keep part 4 score zero if ($q==$f[4] && $r==$tails[4] && $s==$f[4] && $t==$tip[4]) { $v5part=1/6;} # If correct, update part 5 score else { $v5part=0;} # If wrong keep part 5 score zero if ($u==$f[5] && $v==$tails[5] && $w==$f[5] && $x==$tip[5]) { $v6part=1/6;} # If correct, update part 6 score else { $v6part=0;} # If wrong keep part 6 score zero $total_score = $v1part+$v2part+$v3part+$v4part+$v5part+$v6part; # Update total score return ('ASSIGNED_SCORE',$total_score); </answer> <!-- Hidden line stmt req'd to pass submission values to Geogebra app. Changing to textline will show values. --> <hiddenline readonly="no" spellcheck="none" size="80" /> </customresponse> <table> <tr> <td> <!-- This command creates and inserts an element for the Geogebra applet. --> <div id="harmonicsplot_applet_container"></div> </td> <td> <block condition="$ShowHarmPlot"> <!-- Display harmonic vectors answer plot if $ShowHarmPlot == 1 --> <gnuplot width="600" minor_ticscale="0.75" grid="on" align="right" font="9" height="450" border="on" samples="100" bgcolor="xffffff" fgcolor="x000000" alttag="Spectrum Plot" transparent="off" major_ticscale="2" plottype="Cartesian"> <xtics minorfreq="1" location="border" mirror="on" end="$xtic_stop" increment="$xtic_incr" start="0" /> <ytics minorfreq="1" location="border" mirror="on" end="$ytic_stop" increment="2" start="0" /> <axis xmin="$x_min" ymax="$y_max" color="x000000" ymin="$y_min" xmax="$x_max" /> <xlabel>Frequency (MHz)</xlabel> <ylabel>Amplitude (V)</ylabel> <!-- It does not respond to changes in the "linewidth" or "pointsize" parameter values. --> <curve linestyle="vector" linetype="solid" arrowangle="15" color="x000000" arrowstyle="filled" pointtype="4" linewidth="1" arrowhead="head" arrowlength="$arwhd" pointsize="1"> <!-- vector plot requires 4 datasets: X, Y, deltaX, deltaY --> <data>@f</data> <data>@tails</data> <data>@zeros</data> <data>@mag</data> </curve> </gnuplot> </block> </td> </tr> </table> <!-- The next line was only for debugging; not used in final version. --> <!-- <startouttext />Score = $total_score Tries=$tries maxtries=$maxtries ShowHarmPlot=$ShowHarmPlot <br /><endouttext /> --> </part> <part id="b"> <startouttext /><br /><br /> ¤tpart. Plot the signal cross products for m,n equal 1,2. Work from lowest <br /> to highest non-zero frequency. If multiple harmonics occur at the same frequency, <br /> plot them tip to tail from largest to smallest. <br /> If any vectors are not used, place them at the origin with a magnitude of 5 V.<br /> <endouttext /> <customresponse id="22"> <answer type="loncapa/perl"> # These submission variables appear to be local to this (part or custom response) only. ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p, $q,$r,$s,$t,$u,$v,$w,$x,$y,$z,$aa,$bb,$cc,$dd,$ee,$ff) = split(',',$submission); if ($a==$fcp[0] && $b==$tailscp[0] && $c==$fcp[0] && $d==$tipcp[0]) { $v1cppart=1/8;} # If correct, update part 1 score else { $v1cppart=0;} # If wrong keep part 1 score zero if ($e==$fcp[1] && $f==$tailscp[1] && $g==$fcp[1] && $h==$tipcp[1]) { $v2cppart=1/8;} # If correct, update part 2 score else { $v2cppart=0;} # If wrong keep part 2 score zero if ($i==$fcp[2] && $j==$tailscp[2] && $k==$fcp[2] && $l==$tipcp[2]) { $v3cppart=1/8;} # If correct, update part 3 score else { $v3cppart=0;} # If wrong keep part 3 score zero if ($m==$fcp[3] && $n==$tailscp[3] && $o==$fcp[3] && $p==$tipcp[3]) { $v4cppart=1/8;} # If correct, update part 4 score else { $v4cppart=0;} # If wrong keep part 4 score zero if ($q==$fcp[4] && $r==$tailscp[4] && $s==$fcp[4] && $t==$tipcp[4]) { $v5cppart=1/8;} # If correct, update part 5 score else { $v5cppart=0;} # If wrong keep part 5 score zero if ($u==$fcp[5] && $v==$tailscp[5] && $w==$fcp[5] && $x==$tipcp[5]) { $v6cppart=1/8;} # If correct, update part 6 score else { $v6cppart=0;} # If wrong keep part 6 score zero if ($y==$fcp[6] && $z==$tailscp[6] && $aa==$fcp[6] && $bb==$tipcp[6]) { $v7cppart=1/8;} # If correct, update part 7 score else { $v7cppart=0;} # If wrong keep part 7 score zero if ($cc==$fcp[7] && $dd==$tailscp[7] && $ee==$fcp[7] && $ff==$tipcp[7]) { $v8cppart=1/8;} # If correct, update part 8 score else { $v8cppart=0;} # If wrong keep part 8 score zero $total_cpscore = $v1cppart+$v2cppart+$v3cppart+$v4cppart +$v5cppart+$v6cppart+$v7cppart+$v8cppart; # Update total score return ('ASSIGNED_SCORE',$total_cpscore); </answer> <!-- Hidden line stmt req'd to pass submission values to Geogebra app. Changing to textline will show values. --> <hiddenline spellcheck="none" size="80" readonly="no" /> </customresponse> <table> <tr> <td> <!-- This command creates and inserts and element for the Geogebra applet. --> <div id="applet_container2"></div> </td> <td> <block condition="$ShowXProdPlot"> <!-- Display cross product vectors answer plot if $ShowXProdPlot == 1 --> <gnuplot width="600" minor_ticscale="0.75" grid="on" align="right" font="9" height="450" border="on" samples="100" bgcolor="xffffff" fgcolor="x000000" alttag="Spectrum Plot" transparent="off" major_ticscale="2" plottype="Cartesian"> <xtics minorfreq="1" location="border" mirror="on" end="$xtic_stop_cp" increment="$xtic_incr_cp" start="0" /> <ytics minorfreq="1" location="border" mirror="on" end="$ytic_stop_cp" increment="2" start="0" /> <axis xmin="$x_min_cp" ymax="$y_max_cp" color="x000000" ymin="$y_min_cp" xmax="$x_max_cp" /> <xlabel>Frequency (MHz)</xlabel> <ylabel>Amplitude (V)</ylabel> <!-- It does not respond to changes in the "linewidth" or "pointsize" parameter values. --> <curve linestyle="vector" linetype="solid" arrowangle="15" color="x000000" arrowstyle="filled" pointtype="4" linewidth="1" arrowhead="head" arrowlength="$arwhd_cp" pointsize="1"> <!-- Vector plot requires 4 datasets: X, Y, deltaX, deltaY --> <data>@fcp</data> <data>@tailscp</data> <data>@zeroscp</data> <data>@magcp</data> </curve> </gnuplot> </block> </td> </tr> </table> <!-- The next line was only for debugging; not used in final version. --> <!-- <startouttext />Score = $total_cpscore ShowPlot = $ShowXProdPlot<br /> <endouttext /> --> </part> <allow src="/geogebra/deployggb.js" /> <allow src="/res/purdue/ecet_purdue/Topics/Libraries/Eight-vector_Xprod_SpectrumPlot_XaxisMHz_YaxisV_material-dUA5ZHhR.zip" /> <allow src="/res/purdue/ecet_purdue/Topics/Libraries/SixVectors_FreqSpectrum_XAxisMHz_YAxisV_material-umgpsv5X.zip" /> <allow src="/res/purdue/ecet_purdue/Topics/RF/Mixing/SixVectors_FreqSpectrum_material-H9ecmkmh.zip" /> <allow src="/res/purdue/ecet_purdue/Topics/RF/Mixing/SixVectors_FreqSpectrum_material-XwqVj97A.zip" /> </problem>
_______________________________________________ LON-CAPA-users mailing list LON-CAPA-users@mail.lon-capa.org http://mail.lon-capa.org/mailman/listinfo/lon-capa-users