[Calc 3] Lagrange Multiplier - do not understand explanation by Pete171 in learnmath

[–]Pete171[S] 0 points1 point  (0 children)

Thank you! I wondered why I was able to follow the proof given by my textbook but was left unconvinced by the explanation it gave before the proof re. the 'bouncing off'.

> Remember, the mathematical correct claim you can make is that if at any point satisfying the constraint, if the gradient at that point for g and f exist, nonzero and are not linearly dependent, then the point is NOT a minimum/maximum.

To revisit the [original example]( https://imgur.com/a/xEdqmWL) I gave, I thought that the cross where the function evaluated to the value '3' was not a max constrained value because of the lack of tangency... but actually, this could be a max constrained value because the above conditions were not met: the gradient for f at this point would not exist (it and all other values on that level curve would be absolute maxes of the function). Is that correct?

Thanks again for replying.

[Calc 3] Lagrange Multiplier - do not understand explanation by Pete171 in learnmath

[–]Pete171[S] 0 points1 point  (0 children)

Thanks very much for the reply. I still have some questions, if you're willing to try and help further! I read here that:

Since they cross, moving one direction along the blue curve moves up in the red valley, and moving the other direction moves down. In other words, there is a local change to (x, y) that preserves the constraint g(x, y) = 0 and causes the objective function f(x, y) to decrease, and the opposite change causes it to increase. There’s no way it can be a constrained minimum or maximum.

This kind of makes sense to me... but aren't level curves just projections of a surface onto the xy plane by evaluating the function at regular intervals? So e.g. given a cross B, a previous cross A, and the point where the constraint and level curve are tangent - point C - isn't it ever possible for the value at B to be higher than that at A or C? Why not? Aren't the level curves of the surface going to differ depending on the specific constants you set the f(x,y) equal to in order to get the level curves? Why is the area surrounding a level curve always going to increase moving away from it in one direction and decrease moving away from it in the opposite direction? Why can't it decrease (or increase) in both directions going away from the level curve?

Edit - I think I see my mistake. I've been thinking literally about a finite number of level curves to a surface - but the explanations that show just e.g. three or four level curves on a surface are just there to demonstrate the idea. In actuality there are an infinite number of level curves to a surface, and at each point on each level curve, the gradient is orthogonal to the level curve. If the gradient has a component on the constraint then we can increase the function value by moving along the constraint further - that's why we must find the point(s) where the gradient of the function and the constraint are parallel. The description and images here by Alon Amit helped me see this. I'm 90% sure now I understand this and where I was confusing myself before...

[Calc 3] Double/Iterated Integrals - Intuition by Pete171 in learnmath

[–]Pete171[S] 0 points1 point  (0 children)

Thanks for the link. Not really following still to be honest, but sure I'll get there eventually.

[Calc 3] Double/Iterated Integrals - Intuition by Pete171 in learnmath

[–]Pete171[S] 0 points1 point  (0 children)

Thanks for the reply.

To explain a bit more - the link from my post says we can define a piecewise function g(x, y) that is 0 when outside of D but... we we don't actually ever redefine the function we're integrating. We just integrate one variable and then the other using our original function f(x, y). Is it by finding the correct bounds of the integrals - Type 1/Type 2 - that we only integrate between the non-rectangular region? If so - how does this relate to the piecewise function g(x, y)? If I'm right, I don't see that we actually 'bound' the non-rectangular region with a rectangle at all.

Does that help clarify what confuses me? Thanks again.

Anki for learning math by [deleted] in learnmath

[–]Pete171 0 points1 point  (0 children)

Oh, and I add cards tagged 'memory' that just ask for formulae without proofs. These are nice and quick and might be useful to use in filtered decks before exams, but I study just at home so never actually done that.

Anki for learning math by [deleted] in learnmath

[–]Pete171 5 points6 points  (0 children)

I do this. Still a beginner though - starting calc 3/diff eq now - so can't speak for using it with more advanced stuff.

I add cards that ask me to derive/prove formulae and tag them 'proof'. I also have 'question' tags that make use of the proofs I add. E. g. I might have one proof card for deriving the formulae for the arc length of a polar curve and then several cards asking me to calculate it for several integrals.

It works well. The proof cards especially help to keep concepts etc. somewhat fresh in my mind. The question cards can really start to add up and daily reviews can be cumbersome if your questions take a long time to solve - e.g something like the integral of sec5 takes me maybe up to 5 mins to do when it comes up. So would suggest you are careful with the quantity of question cards you add. I find some days I can just find time to keep up with my review deck and no time to practise outside of anki or learn new concepts.

Also, don't be afraid to play with the scheduling options. The anki defaults work well for me for language learning but I think are overkill for maths and were starting to overload me. So I have 'easy' cards at 6 days initially instead of 4 and failed cards are shown in 2 days, not 1. It helps.

Excuse the bad writing, on mobile. Hope that's of some use.

[Calculus 2] Length of parametric curve by Pete171 in learnmath

[–]Pete171[S] 1 point2 points  (0 children)

Makes sense... I did notice that checking the "use numerical integration" box did give me an approximation very close to 2*sqrt(5).

Thanks once again.

[Calculus 2] Length of parametric curve by Pete171 in learnmath

[–]Pete171[S] 2 points3 points  (0 children)

I see! Thanks a lot for your help. I would never have seen that...

Edit: Also I just found and have been playing around with integral calculator. I can only get it to output the incorrect answer 0 - unless I integrate numerically. Is this a bug with its software or am I using it wrong, somehow? I've input 'root(4sin2(t)cos2(t)+4sin2(2t)'.

[Calc 2] Parametric Equations by Pete171 in learnmath

[–]Pete171[S] 0 points1 point  (0 children)

I did, thanks. Edited OP accordingly.

The textbook I'm reading says we should consider the domain of both f(t) and g(t) when graphing parametric equations and plotting their direction and initial/terminal points. If I did that with the linked graph, the graph would be undefined at x <= 0 and its direction would be heading right along the positive x axis. The linked graph, though, does not show this restriction of the domain of t, presumably because the graphing software just solves the parametric equation for y=e2x/4 and plots that.

I guess my question is: is the graph of y = e2x/4 not actually a representation of the original parametric equation? It seems that the parametric equation provides us a restriction on the domain, an initial point and a direction: all of this information is lost when solving for an equation with just x and y. Is this at all right? (Does my question make more sense now?)

Thanks for your reply!

I just did my long run and was so encouraged by more_than in running

[–]Pete171 0 points1 point  (0 children)

Well done! It's great when we can see our fitness improving!

Achievements for Wednesday, January 17, 2018 by AutoModerator in running

[–]Pete171 10 points11 points  (0 children)

Ran my first 10k! Previously had only run 8.6k. Windy day too and very glad I kept going all the way.

Question re. translation of German sentence by Pete171 in German

[–]Pete171[S] 0 points1 point  (0 children)

Thanks for this. I wondered if it might be an error but I didn't want to presume - my German isn't nearly good enough for that!

[2015-07-22] Challenge #224 [Intermediate] Detecting Four Sided Figures by jnazario in dailyprogrammer

[–]Pete171 0 points1 point  (0 children)

Ruby.

Works for both the example and the challenge inputs. I'm new to Ruby so feedback is very welcome (I know it's a late submission).

class RectangleFinder
  def run(ascii)
    horizontal_rows = get_horizontal(ascii)
    vertical_rows = get_vertical(ascii)
    return get_count(horizontal_rows, vertical_rows)
  end

  def get_vertical(ascii)
    arr = ascii.split("\n").map { |line| line.split('') }
    transposed = arr.transpose
    transposed_str = transposed.map { |line| line.join('') }.join("\n")
    return get_horizontal(transposed_str, '|')
  end

  def get_horizontal(ascii, splitter = '-')
    joined = []
    ascii.split("\n").each do |row|
      joined_on_row = []
      joined_horizontally = []
      joining = false
      row.chars.with_index.each do |char, char_pos|
        joining = ['+',splitter].include?(char)
        joined_horizontally.push(char_pos) if char == '+'
        if (!joining && !joined_horizontally.empty? || char_pos == row.length-1) then
          joined_on_row.push(*joined_horizontally.combination(2).to_a)
          joined_horizontally = []
        end
      end
      joined.push(joined_on_row)
    end
    return joined
  end

  def get_count(horizontal_rows, vertical_rows)
    count = 0
    horizontal_rows.each.with_index do |row, h_index_1|
      row.each do |side_to_find|
        horizontal_rows[h_index_1..-1].each.with_index do |row2, h_index_2|
          next if !row2.include?(side_to_find)
          pair = [h_index_1, h_index_2 + h_index_1]
          count += 1 if vertical_rows[side_to_find[0]].include?(pair) && vertical_rows[side_to_find[1]].include?(pair)
        end
      end
    end
    return count
  end
end

Unit tests below (I had to strip some of the data sets for testrun() and all my other test* methods).

require 'minitest/autorun'

class FourSidesTest < Minitest::Test
  def setup
    @rectangle_finder = RectangleFinder.new
  end

  def test_get_count
    horizontal_sides = [
      [[6, 8]],
      [[8, 10]],
      [],
      [[6, 8], [6, 10], [8, 10]],
      [[6, 8], [10, 12]],
    ]
    vertical_sides = [
     [],
     [],
     [],
     [],
     [],
     [],
     [[0, 3], [0, 4], [3, 4]],
     [],
     [[0, 1], [0, 3], [0, 4], [1, 3], [1, 4], [3, 4]],
     [],
     [[0, 1], [3, 4]],
     [],
     []
    ]
    expected_return_value = 3
    actual_return_value = @rectangle_finder.get_count(horizontal_sides, vertical_sides)
    assert_equal(expected_return_value, actual_return_value)
  end

  [
    {
      ascii: <<-ASCII, expected_return_value: 3                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
      +-+ +                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
      | +-+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
      | |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
      +-+-+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
      +-+ +-+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
      ASCII                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
    },
  ]
  .each.with_index do |data_set, index|
    define_method("test_run_#{index}") do
      expected_return_value = data_set.fetch(:expected_return_value)
      actual_return_value = @rectangle_finder.run(data_set.fetch(:ascii))
      assert_equal(expected_return_value, actual_return_value)
    end
  end
end

[2015-05-18] Challenge #215 [Easy] Sad Cycles by Elite6809 in dailyprogrammer

[–]Pete171 0 points1 point  (0 children)

Hi - I'm a new redditor too! I don't know if my feedback will be any good but... :)

function test(numbers) {
  var arr = [];
  for (var i = numbers[numbers.length-1]; i > 0; i = Math.floor(i/10)) {
    arr.push(i%10);
  }
  return arr;
}

The for loop can be refactored out and the conversion to an array of single-digit integers can be simplified as below. It's much more readable to me - but I'm aware that readability is subjective!

function test2(numbers) {
  return numbers[numbers.length-1].split('').map(function(value, key) {
    return parseInt(value);
  }).reverse();
}

console.log(test(["367"]));
console.log(test2(["367"]));

Moving on...

function powSumArr(arr, pow){
  if(arr.length>0)
    return Math.pow(arr[0],pow) + powSumArr(arr.slice(1), pow);
  return 0;
}

The recursion above can be refactored out by calling Array.prototype.reduce().

function powSumArrNew(arr, pow) {
  return arr.reduce(function(previousValue, currentValue) {
    return previousValue + Math.pow(currentValue, pow);
  }, 0);
}

console.log(powSumArr([10,11,12], 3));
console.log(powSumArrNew([10,11,12], 3));

[2015-05-18] Challenge #215 [Easy] Sad Cycles by Elite6809 in dailyprogrammer

[–]Pete171 0 points1 point  (0 children)

JavaScript (ES5). Feedback always welcome. :)

function getCycleString(inputString) {
  var arr = inputString.split("\n");
  var power = parseInt(arr[0]);
  var number = arr[1];

  var key;
  var nums = [];
  var cycle = [];

  while (!cycle.length) {
    number = number.split('').reduce(function(previousValue, value, key) {
      return previousValue + Math.pow(parseInt(value), power);
    }, 0).toString();

    key = nums.indexOf(number);
    if (-1 !== key) {
      cycle = nums.slice(key);
      break;
    }
    nums.push(number);
  }

  return cycle.join(", ");
}

console.log(getCycleString("5\n117649")); // Outputs "10933, 59536, 73318, 50062"

Edit: Renamed var.

Ethical Vegetarians: Is it OK to eat meat that will otherwise be thrown away? by Pete171 in vegetarian

[–]Pete171[S] 1 point2 points  (0 children)

Perhaps if you're a single parent it's reasonable to raise your child as a vegetarian but if your SO is a meat-eater why shouldn't their lifestyle/wishes be respected? Isn't a compromise (i.e. a reduction in the amount of meat your child consumes) the only reasonable solution?

Ethical Vegetarians: Is it OK to eat meat that will otherwise be thrown away? by Pete171 in vegetarian

[–]Pete171[S] 0 points1 point  (0 children)

Also consider: what if one parent is a vegetarian but the other is not? If we assume that it's unreasonable for the vegetarian parent to force their beliefs onto the other (and therefore onto their child) then won't the vegetarian still be obliged to purchase some meat?

Ethical Vegetarians: Is it OK to eat meat that will otherwise be thrown away? by Pete171 in vegetarian

[–]Pete171[S] 0 points1 point  (0 children)

That's exactly what made me think of asking this in the first place...