Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Mathcad to Matlab

Tags:
  1. Oct 29, 2008 #1
    how can someone do the attach calculation in Matlab?
     

    Attached Files:

  2. jcsd
  3. Oct 29, 2008 #2
    Read the documentation. The Matlab getting started guide is particularly good, and will teach you how to perform calculations like this and more.
     
  4. Oct 29, 2008 #3
    i went through it but i couldnt get to work.. this is what i did:

    for i = 0 : 100
    for j = 1 : 101


    dme = (sum (sum ((i/j)^ 2)+log(sqrt(j))));
    end
    end
     
  5. Oct 29, 2008 #4
    how about this

    for i = 0 : 100
    for j = 1 : 101
    x= (i/j)^2;
    y = (j)^.5;
    end
    end


    F = (sum (x)+log(y))

    but the answer is not consistent with the mathcad ansr
     
  6. Oct 29, 2008 #5
    There are a couple of important things to note.

    Firstly, Mathcad is an infamously flaky piece of software. Use it only if you have absolutely no alternative.


    Secondly, the answer you've got from Mathcad is incorrect. The actual result of the summation you've given is

    [tex]\sum_{i=0}^{100} \sum_{j=1}^{101} \left[ \left(\frac{i}{j}\right)^2 + \log\sqrt{j} \right] \approx 571831.873[/tex]

    You can verify this using Mathematica, Maple, Matlab, or your own C/C++/Python code. Again let me stress: Mathcad is absolutely atrocious software. I've seen the source, and it's not pretty. Avoid it like the plague.


    Thirdly, to evaluate the sum in Matlab you can do something like the following:

    Code (Text):

    % First declare and initialize a dummy variable
    x = 0;

    % Now perform the summation:
    for i = 0:100
    for j = 1:101
    x = x + (i / j)^2 + log(sqrt(j));
    end
    end
     
    This should leave you with the variable x holding the result. Note that this is neither a particularly efficient nor elegant way of computing such a sum.
     
  7. Oct 30, 2008 #6
    Actually the mathcad result is correct. In matlab, log means ln, log10 means log.The answer shoehorn gives is for ln.
    so the code is
    % First declare and initialize a dummy variable
    x = 0;

    % Now perform the summation:
    for i = 0:100
    for j = 1:101
    x = x + (i / j)^2 + log10(sqrt(j));
    end
    end
     
    Last edited: Oct 30, 2008
  8. Oct 30, 2008 #7
    Thank you to shoehorn and to Emreth ..
     
  9. Oct 30, 2008 #8
    since we r in the topic; how can i plot the attach equation between [-4,4] with a 0.001 interval using matlab

    thanks in advance
     

    Attached Files:

  10. Oct 30, 2008 #9
    read the help files, this is quite trivial.

    for i=1:3000
    x(i)=-4+i/1000;
    y(i)=-x^2-4*x-2;
    end
    for i=3000:5000
    x(i)=-4+i/1000;
    y(i)=abs(x);
    end
    for i=5000:8000
    x(i)=-4+i/1000;
    y(i)=2-exp(sqrt(x-1));
    end
    plot(x,y);
     
    Last edited: Oct 30, 2008
  11. Oct 30, 2008 #10
    Tip of the Hat to Emreth ..

    the way u wrote x(i) ,, is smart... once again thanks
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Mathcad to Matlab
  1. Mathcad 14 (Replies: 5)

  2. Mathcad Function (Replies: 1)

Loading...