Code Definition and 908 Threads

  1. R

    Why is the complexity of this code O(n^2)?

    def fib(n): f0, f1, = 0, 1 for i in range(n - 1): f0, f1 = f1, f0 + f1 return f1 It looks like it'd be linear, given there's only one loop, but when I plotted n against runtime, the relationship was quadratic, why?
  2. Sneakatone

    How to make a mathematica code with vectors and magnitude

    Homework Statement Create a mathematica code to add arbitrary number of 3 dimensional vectors. 1. n: the number of vectors which must be added 2. For each input vector, the code should accept the following: a. Length of the vector b. Three angles which the vector makes with x, y, and z...
  3. D

    Calculating number of steps in multiple loop piece of code

    Homework Statement The following pseudocode demonstrates an algorithm to create a 2D array from a 1D array by adding elements into certain rows: For i = 1, 2, ..., n For j = i + 1, i + 2, ..., n Add up array entries A[i] through A[j] Store the result in B[i, j] Endfor...
  4. W

    Python Problem with python code. Combinations of 2-state vectors

    I am trying to find all combinations of a four element vector that contains only 1's and -1's. Ex (1,1,1,1),(-1,1,1,1),...(-1,-1,-1,-1) etc My idea to do this is pretty inefficient I am sure but I can't think of another way to do it, so here is what I was trying to do. I found how many total...
  5. J

    C/C++ Critique of C++ code for encoding and decoding text

    These are some functions I'm using to encode and decode text. [FONT="Courier New"]bitstring returns a string of bits representing the ascii values of the characters in the string passed to the function. For example, passing in "Hi" changes it to "0100100001101001" since (int)'H'=72=01001000...
  6. A

    Fortran Identify explicit shape spec list in the FORTRAN code

    Identify "explicit shape spec list" in the FORTRAN code Hi, I'm trying to do some source code analysis using the ROSE compiler infrastructure on some of the kernels in NAS Parallel benchmark. I get an error while parsing the Embarrassingly Parallel kernel. Digging further, I gathered that...
  7. P

    How to Resolve Linker Errors When Compiling CPP Code in MATLAB?

    Dear All I am a biologist trying hard to make it in the world of informatics and computing and I was wondering if one of you real scientists could help me. I have a executable program with its associated .lib .exp and .pdb files. I thought I could easily mex the cpp of this excutable...
  8. J

    Is there anything wrong with this C code?

    I had an interview the other day and the lady was asking me about different ways to find whether there are any repeated elements in an array. At the end of the interview she told me to send her a code sample showing how to implement two of the ways we discussed. I thought that what I wrote was...
  9. K

    Fortran Can't get Fortran code to give me desired output file

    Hey everyone, I have written a Fortran code for a project I am working on, but am having an issue: I can't get the code to output my data to the file I have opened. Here is what I am trying to do. I am setting up a Monte-Carlo code that selects a random x- and y-value. These values are...
  10. B

    How to Compute Convolution Using FFT in Matlab?

    Homework Statement You have two functions in Matlab (represented as column vectors). Compute their convolution using the fast Fourier transform. Homework Equations The Attempt at a Solution I am having trouble finding a book with this topic. I would like to know where the...
  11. L

    Fortran Segmentation error form the fortran code

    Hi Forum users I have a velocity autocorrelation code which was made to read a three component velocity vectors and I have modified to read a 9 component stress tensor data. I can compile it successfully but when I try to run it and compute a stress correlation function I get an error: i.e...
  12. G

    MATLAB code for generating PPM :

    Hi all, I am quite new to MATLAB . I would like some help on the following: generation of Pulse Position Modulation using a MATLAB code. thank you :)
  13. Farmtalk

    MHB Unlock the Code - Solve the Challenge!

    [FONT=Verdana]Here is another challenge that I thought was fun :cool:[FONT=Verdana] A man wanted to get into his work building, but he had forgotten his code. However, he did remember five clues. These are what those clues were: [FONT=Verdana]The fifth number plus the third number equals...
  14. W

    How to Create MATLAB Code for Geometrical Optics Image Transformation?

    Hello all, i have frustrating task in my lab... i have to generate a code in MATLAB that will get the focal length and the object distance from the lens, i.e image (1000X1000 pixels). transfer it through the lens and, for the output it should be the result of it...
  15. A

    MHB Weight and distance of a binary code

    Is there a relationship between the distance and weight of a binary code? I want to find the weight and distance of the code consisting of the codewords: 0000 0000 0010 1110 0101 1100 1011 1010 1110 0101 1100 1011 0111 0011 1001 0111 (spaces inserted for readability) The weight can be checked...
  16. S

    Code water thermodynamic properties (enthelpy)

    Hi everyone, I would like to program water thermodynamic properties in C, C++ or Matlab in order to model a steam power plant. I'm particularly interested in getting the enthalpy of the fluid by knowing the temperature and the pressure. I recently found out the software Cantera...
  17. E

    LaTeX What is wrong in this Latex code?

    Hi, I have the following Latex code, which is perfectly working under the class report, but when I change the class report to beamer to make slides, I get errors. Why? \documentclass{report} %\documentclass{beamer} %\setbeamertemplate{navigation symbols}{}...
  18. E

    How to correctly code the expression with Ei function?

    Hi, I am trying to incorporate the following equation into Matlab in the red: http://http://www.radikal.ru][PLAIN]http://s018.radikal.ru/i518/1305/16/1cc0d2a72d38.jpg The following data is to be used: t=3000000 nr=nx=161 q=0.02 k=5e-13 mu=0.00035 c=1.5e-8 phi=0.25 rw=0.1 h=4.5...
  19. B

    Does a hamming code always corrects one error and detect 2 errors ?

    does a hamming code always corrects one error and detect 2 errors ? and is the distance always 3 ? I know that that is true for (7,4) hamming code but does that apply to a (11,7) or (15,11) ? if not please let me how to get the answers
  20. B

    Matlab code for solving and plotting function x'(t) = 1 + t*sin(t*x)

    Homework Statement I am trying to solve and plot the function, x'(t) = 1 + t*sin(t*x) where x(0) = 0 and t_final = 1, in order to compare this exact solution to the approximations of Euler's and Improved Euler's Method. Can anyone help me with the code in order to solve this problem, and then...
  21. B

    MATLAB Matlab Code for solving and plotting function x'(t) = 1 + t*sin(t*x)

    Hi everyone, I am trying to solve and plot the function, x'(t) = 1 + t*sin(t*x) where x(0) = 0 and t_final = 1, in order to compare this exact solution to the approximations of Euler's and Improved Euler's Method. Can anyone help me with the code in order to solve this problem, and then plot...
  22. J

    Mathematica Problems with Mathematica Code for Markov Models?

    Hello! I'm writing a paper where I'm going to use markov models to evalute a device. My base for this paper is the paper written by H. Timbley. I have never used Mathematica before and thought that I would start by trying the complete code that Timbley has written in the appendix of the paper...
  23. jtbell

    News Sioux City makes lemonade out of a lemon (their airport code)

    Sioux City SUX, and that's OK (CNN.com)
  24. B

    Help in upgrading my code that converts a lower-case string to upper c

    hello I'm a beginner in c programming. I wrote a code that converts the lower case that the user entered to upper case characters. I want to improve my program , but since I'm a beginner i might not be aware of some technics . my program can only allow you to enter as many characters as...
  25. R

    MATLAB Matlab code for detection of location of a crack using natural frequen

    please help i have to write a MATLAB code for DETECTION OF THE LOCATION AND SIZE OF A CRACK IN STEPPED CANTILEVER BEAMS BASED ON MEASUREMENTS OF NATURAL FREQUENCIES the reference paper is DETECTION OF THE LOCATION AND SIZE OF A CRACK IN STEPPED CANTILEVER BEAMS BASED ON MEASUREMENTS OF...
  26. R

    A code for (alpha,gamma) reaction

    Hi I want to define an Am-Be source in MCNPX 2.6 But I don't have Gamma spectra of this source. Is there any computer code that can simulate (Alpha,Gamma) reaction? Please Help!
  27. J

    Python Python program help with my math code

    Hi I built this code that runs well. Is about calculating a student loan... The problem is that I wish I could create a table that will tell me in each column "payment number", "remaining balance", "interest amount", "principal amount" Can you help me do this? I am new to python and this is not...
  28. R

    MATLAB Matlab: what is the right 3D plotting function for my code?

    Hi all, I have a simple question about 3D plotting. Consider this simple loop, which provides y and O for any x. and I am able to plot y vs O for given x. for Omega=0:.01:5 y(i)=(x*Omega^2); O(i)=Omega; i=i+1; end now consider I want to change the value of x, for x=0:.1:3...
  29. S

    How to Implement Kramers-Kronig in Mathematica for CSV Data?

    Homework Statement I'm trying to write Mathematica code to use Kramers-Kronig on a csv file with 2 columns. Column 1 is h(eV). It goes from 0 to 6, in increments of 0.1. Column 2 is alpha (cm^-1). In the equation below, I'm guessing column 1 is Ω. But what should I put in for ω?Homework...
  30. E

    MATLAB How code the following expression into Matlab

    Hey, guys How can the following equation be entered into matlab: http://i074.radikal.ru/1304/fe/a8b8e0fccbe5.png Thakns.
  31. E

    Determining PSD of 1uaternary (4-ary) line code

    Homework Statement Ok So this is an example from my text. I am having trouble following a portion of it and was curious if anyone could shed some light on it. I've typed most of it and posted a screen shot of the second portion since there is a table involved. Determine the PSD of the...
  32. I

    MATLAB Decoding a Playfair Code with Matlab: Tips and Tricks

    Hi all, I hope my post is in the right section. I need some help with decoding a Playfair code. I only have the ciphertext which is 22 lines long. What's the best way to do this? I red that I have to do some frequency analysis of the English bigrams which I did. There's one combination which...
  33. Farmtalk

    MHB Crack the Code: A Puzzle Challenge!

    I posted this on my website a couple days ago. I like puzzles a lot, so I figured I would share it here and see how many people could figure it out; enjoy!;) A man wanted to get into his work building, but he had forgotten his code. However, he did remember five clues. These are what those...
  34. N

    C/C++ How can I parallelize my C++ code to utilize multiple cores?

    Hi I have written an extensive simulation in C++ and when I run it on my quad-core machine, only a single core is used (on Windows). This is because my code is not parallelized. I'm not familiar in any way with code running in parallel, except in Matlab where is happens almost...
  35. A

    C/C++ How to Handle an Infinite Loop in C/C++ Code?

    Hello there! I typed this code and saved it as a .c file #include<stdio.h> #include<stdlib.h> #include<conio.h> int main() { int a; while(1) { if (kbhit()) { system("cls"); printf("%d...
  36. B

    Troubleshooting Code for Sets: \mathbb{N}

    I searched for this but couldn't find a sol. when entering the code for sets i.e. \mathbb{N} I get this error message: ! Undefined control sequence. <recently read> \mathbb l.32 $\mathbb{N}$ The control sequence at the end of the top line of your error message was never \def'ed. If...
  37. R

    Fortran Why Is My FORTRAN If/Else Statement Not Working Correctly?

    I am not able to get what's wrong in below. IF ( temp < 97.5 ) THEN WRITE (*, *) NTemperature below normalN ELSE IF ( temp > 97.5) THEN WRITE (*, *) NTemperature normalN ELSE IF ( temp > 99.5) THEN WRITE (*, *) NTemperature slightly highN ELSE IF ( temp > 103.0) THEN WRITE (*, *)...
  38. R

    Fortran How Can I Improve My Fortran Program for Calculating Different Types of Means?

    Trying to write a single Fortran program that calculates the arithmetic mean, rms (root-mean-square) average, geometric mean, and harmonic mean for a set of numbers (for example - 4 4 4 4 4). I don't know if I am doing the write way. Please guide me. PROGRAM ComputingMeans IMPLICIT...
  39. K

    Is a Suit Necessary for Presenting at Physics Conferences?

    I'm going to be attending and presenting at my first large physics conference this spring. I'm trying to get my dad to help me buy a suit for the day I present. However, my dad (an experienced biochemist) refuses, not because of money, but because he claims "nobody ever wears suits to those...
  40. S

    C/C++ What is the significance of this C++ code and what does it do?

    Hey guys. I just want to see if I am indeed "seeing" the significance of the code that is to follow. I will follow it with a brief explanation of what I thought the code did. Thanks in advance. const int N = 15; bool table[N]; int i = 0; while (i < N) { table[i] = true...
  41. M

    What Are the Different Methods to Define a Plate in MCNP Code?

    I have a question about diffrence between ways of defining a certain plate like (3^1/2)x+y+17.3=0 to MCNP code .for example I know we can define it to MCNP with 15 p 3 2 0 6 but I couldn't understand this method 15 10 0 5 8.66 0 10 0 1
  42. F

    Fortran Why Am I Getting a Parenthesis Error in FORTRAN Code Compilation?

    Hello, I received some very old cold, and I don't even know for which FORTRAN standard it was originally written, only that it has existed since at least 1993. I'm trying to compile it in gfortran, and I get the following error: 'Error: Expected a right parenthesis in expression at (1)'...
  43. E

    Is the gray code arithmetic code ?

    hi is the gray code arithmetic code?why? where this code used?
  44. T

    MATLAB help, code for Frobenius norm

    Hello, I am trying to write a mtlab code to compute Frobenius norm of an mxn matrix A. defined by ||A||_{F} = \sqrt{ \sum_{i=1}^m \sum_{j=1}^n a^{2}_{i,j}} I have so far written this code, but it does not work, if anyone can help /guide me to the right path, would be greatly...
  45. M

    Confusions about Position Independent Code

    Hello! I was reading this excellent article about position independent code and it's implementation for shared libraries. I'm still confused about one part though. My current understanding is that the offset between the code section and data section is known at compile time. Since this offset...
  46. C

    Calculators How to put code on MS WORD onto TI-89

    My Thermodynamics teacher gave me a code for various calculators to put into the calculator for Interpolation. I am just wondering how you put this code that is in MS WORD onto my TI-89. I have the TI-Connect software. Here is what is looks like: This code is for the TI-89: interpol()...
  47. M

    Fortran Error 112 /undef when running fortran code

    Hi, I am a new Fortran User. I have a problem when I run my code (not errors during building), in fact the code is stopped in the last line and this message appears "Error 112, Reference to undefined variable, array elements or function result" ... write(number,100)k1 open...
  48. Fredrik

    LaTeX An exact copy of a working LaTeX code doesn't work?

    An exact copy of a working LaTeX code doesn't work!? OK, someone needs to explain this to me, because my head is about to explode. Forum member Jorriss has a LaTeX code in his signature. It includes the LaTeX code \Psi in two places. The second one is displayed correctly. The first one isn't...
  49. K

    Cracking the Code: Solving Cylindrical Shells with Gauss's Law

    Homework Statement "A cylindrical shell of length 230 m and radius 6 cm carries a uniform surface charge density of σ = 14 nC/m^2. What is the total charge on the shell? Find the electric field at the end of a radial distance of 3 cm from the long axis of the cylinder." Homework Equations...
  50. Y

    Fortran A FORTRAN code for solving Sudoku puzzle

    For few days I am thinking to write a code in FORTRAN to solve the sudoku puzzle. At first it seams simple but I have no luck writing this code. I am wondering if there is any written code to solve this puzzle. I hope Sudoku puzzle is known for members here. en.wikipedia.org/wiki/Sudoku
Back
Top