Matrix chain multiplication dynamic programming (C++ code) Get link Facebook Twitter Pinterest Email Other Apps January 10, 2015 #include<iostream>#include<cstdlib>#define SZ 10using namespace std;int table[SZ][SZ];int P[] = {1, 2, 3, 4, 3};int MCM(int i, int j){ if(i==j) return 0; else { int min = INT_MAX; for(int k=i;k<j;k++) // bug was here: for(int k=i;k<=j;k++) { if(table[i][k]==0) table[i][k] = MCM(i,k); if(table[k+1][j]==0) table[k+1][j] = MCM(k+1,j); int sum = table[i][k] + table[k+1][j] + P[i-1]*P[j]*P[k]; if(sum<min) min = sum; } return min; }}int main(){ int size = sizeof(P)/sizeof(P[0]); printf("Minimum number of mutiplications is %d",MCM(1,size-1)); return 0;} Get link Facebook Twitter Pinterest Email Other Apps Comments
Prime number program code in Scilab August 12, 2014 x=input("Enter any number ");flag=0;for i = 2:(x-1) if(modulo(x,i)==0) then flag=1; break; end;endif(flag==1) then disp("not prime number");else disp("prime number");end; Read more
MATLAB code for Circular Convolution using Matrix method April 22, 2014 % circular convolution using matrix method %clc;x=[1,2,3,1];h=[4,3,2,2];H=zeros(0);h_index=1;N=length(x);y=zeros(0);disp('x(n)=');disp(x);disp('h(n)=');disp(h);subplot(4,1,1);stem(x);title('Signal One : x(n) ');subplot(4,1,2);stem(h);title('Signal Two : h(n)');temp=0;for i=1:NH(i,1)=h(i);end;for i=2:N h=circshift(h, [0,1]); for j=1:N H(j,i)= h(j); end;end;disp('H =>>');disp(H);for i=1:N for j=1:N temp=temp+H(i,j)*x(j); end; y(i)=temp; temp=0;end;disp('Circular Convolution : y(m)==>');disp(y);subplot(4,1,3);stem(y);title('Circular Convolution: y(m)'); Output: Read more
Positive number pipe in angular 2+ December 21, 2019 Code: import {Pipe, PipeTransform} from '@angular/core'; @Pipe({ name: 'positive' }) export class PositivePipe implements PipeTransform { transform(value: number, args?: any): any { return Math.abs(value); } } How to use: {{ someNumber| positive }} Read more
Comments
Post a Comment