Saturday, 13 April 2019

LR

H = c(151, 174, 138, 186, 128, 136, 179, 163, 152, 131)

W = c(63, 81, 56, 91, 47, 57, 76, 72, 62, 48)

relation = lm(W~H)

# Find weight of a person with height 170.

a = data.frame(H = 170)
result = predict(relation,a)
print(result)

DT

install.packages("party")
library(party)

View(readingSkills)
input = readingSkills[c(1:105),]
View(input)

output= ctree(
nativeSpeaker ~ age + shoeSize + score,
data = input)

plot(output)

Tuesday, 2 April 2019

CDAC table

library(shiny)
ui <- fluidPage(
   titlePanel("TABLE"),
    sidebarLayout(
      sidebarPanel(
        sliderInput("num", "integer", 1, 20, 1,
                    step = 1, animate =
                      animationOptions(interval=400, loop=TRUE))),
      mainPanel(
        tableOutput("prod")
      )) )
 
server <- function(input, output) {
    output$prod <- renderPrint({ x<-input$num
    for(i in 1:10){
      a=x*i
      cat(x,"x",i,"=",a,"<br>")
       }})}

shinyApp(ui = ui, server = server)

Thursday, 28 March 2019

EVM Solidity

pragma solidity ^0.4.21;
contract Election{
    struct Canditate{
        string name;
        uint voteCount;
    }
    struct Voter{
        bool authorized;
        bool voted;
        uint vote;
    }
    address public owner;
    string public electionName;
   
    mapping(address => Voter) public Voters;
    Canditate[] public Canditates;
    uint public totalVotes;
   
    modifier ownerOnly(){
        require(msg.sender == owner);
        _;
    }
    function Election(string _name) public {
        owner = msg.sender;
        electionName = _name;
    }
    function getNumberCandidates() public view returns(uint) {
        return Canditates.length;
    }
    function addCandidate(string _name) ownerOnly public {
        Canditates.push(Canditate(_name,0));
    }
    function authorize(address _person) ownerOnly public {
        Voters[_person].authorized = true;
    }
    function vote(uint _voterIndex) public {
        require(!Voters[msg.sender].voted);
        require(Voters[msg.sender].authorized);
       
        Voters[msg.sender].vote = _voterIndex;
        Voters[msg.sender].voted = true;
         Canditates[_voterIndex].voteCount += 1;
         totalVotes += 1;
    }
   
    function end() ownerOnly public {
        selfdestruct(owner);
    }}

Wednesday, 27 March 2019

solidity code

pragma solidity ^0.4.0;
contract SimpleStorage{
    uint a;
    uint shop_1=0;
    uint shop_2=0;
    function initial( uint balu)public{
        a = balu;
    }
     function Shop1( uint balu)public{
        a = a-balu;
        shop_1=shop_1+balu;
    }
     function Shop2(uint balu)public{
          a = a-balu;
          shop_2=shop_2+balu;
    }
     function add(uint balu)public{
          a = a+balu;
    }
    function balance()public constant returns(uint){
        return a;
    }
     function shop_1balance()public constant returns(uint){
        return shop_1;
    } function shop_2balance()public constant returns(uint){
        return shop_2;
    }
    
}

Monday, 18 March 2019

DHT11

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "       "; //Enter the Auth code which was send by Blink

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "     ";  //Enter your WIFI Name
char pass[] = "     ";  //Enter your WIFI Password

#define DHTPIN 2          // Digital pin 4

// Uncomment whatever type you're using!
#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, h);  //V5 is for Humidity
  Blynk.virtualWrite(V6, t);  //V6 is for Temperature
}

void setup()
{
  Serial.begin(9600); // See the connection status in Serial Monitor
  Blynk.begin(auth, ssid, pass);

  dht.begin();

  // Setup a function to be called every second
  timer.setInterval(1000L, sendSensor);
}

void loop()
{
  Blynk.run(); // Initiates Blynk
  timer.run(); // Initiates SimpleTimer
}

Sunday, 17 March 2019

DT

input=readingSkills[c(1:105),]               
output=ctree(nativeSpeaker~age+shoeSize+score,data=input)
plot(output)

ML1

x <- c(151, 174, 138, 186, 128, 136, 179, 163, 152, 131)
y <- c(63, 81, 56, 91, 47, 57, 76, 72, 62, 48)

 relation <- lm(y~x)

a <- data.frame(x=170)
result <- predict(relation,a) print(result)