Assignment for Lab1

Write the program to generate tensorboard graph for below equations.

The code and images should be uploaded to your own repository

In [2]:
#(a−b)2=a2+b2−2ab

import tensorflow as tf
a=4
b=2


with tf.name_scope("lab1_assgn1"):
    with tf.name_scope("Scope_A"):
        x = tf.multiply(a, a)
        y = tf.multiply(b, b)
    with tf.name_scope("Scope_B"):
        z = tf.multiply(2, a)
        h = tf.multiply(z, b)

with tf.name_scope("Scope_C"):
    d = tf.add(x, y)
    s = tf.subtract(d, h)



with tf.Session() as sess:
    writer = tf.summary.FileWriter("/tmp/tboard/output4", sess.graph)
    print(sess.run(s))
    writer.close()


4

In [5]:
#(a3+b3)=(a+b)(a2−ab+b2)

import tensorflow as tf
v1=tf.constant(8)
v2=tf.constant(4)
with tf.name_scope("MyOperationGroup"):
    with tf.name_scope("Scope_A"):
        a = tf.multiply(v1,v1)
        b = tf.multiply(v2,v2)  
with tf.name_scope("Scope_B"):
    c = tf.add(a, b, name="And_These_ones")
    d = tf.multiply(v1, v2, name="Multiply_these_numbers")

with tf.name_scope("Scope_C"):
    e=tf.subtract(c,d, name="subtrating")
   
    f=tf.add(v1,v2)
   
with tf.name_scope("Scope_D"):
    g = tf.multiply(f,e)


with tf.Session() as lb2:
    writer = tf.summary.FileWriter("/tmp/tboard/output5", lb2.graph)
    print(lb2.run(g))
    writer.close()


576

Slot : A1

  1. $$ (a+b)^2 = a^2 + b^2 + 2ab $$
  2. $$ (a+b+c)^2 = a^2 + b^2 + 2ab +2bc + 2ca $$

Slot : A2

  1. $$ (a-b)^2 = a^2 + b^2 - 2ab $$
  2. $$ (a^3+ b^3) = (a+b)(a^2 -ab + b^2) $$

Slot : B1

  1. $$ (a+b)^2 = a^2 + b^2 + 2ab $$
  2. $$ (a^3 - b^3) = (a- b)(a^2 + ab + b^2) $$

Slot : B2

  1. $$ (a-b)^2 = a^2 + b^2 - 2ab $$
  2. $$ (a-b-c)^2 = a^2 + b^2 + c^2 -2ab -2ca + 2bc $$

Slot : C1

  1. $$ (a+b)^2 = a^2 + b^2 + 2ab $$
  2. $$ (a-b+c) ^2 = a^2 +b^2 + c^2 -2xy -2yz + 2xz$$

Slot : C2

  1. $$ (a-b)^2 = a^2 + b^2 - 2ab $$
  2. $$ (a+b)^3 = a^3 + b^3 + 3ab(a+b) $$

Slot D1

  1. $$ (a+b)^2 = a^2 + b^2 + 2ab $$
  2. $$ (a-b)^3 = a^3 - b^3 + 3ab(a-b) $$

Slot D2

  1. $$ (a-b)^2 = a^2 + b^2 - 2ab $$
  2. $$ (a + b-c) ^2 = a^2 + b^2 + c^2 + 2xy -2yz -2xz $$