Doing Attached Calculation in Matlab

Click For Summary

Discussion Overview

The discussion revolves around performing a specific calculation in Matlab, with participants sharing their code snippets, experiences, and results. The conversation includes aspects of programming, debugging, and comparing results with another software, Mathcad.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • One participant inquires about how to perform a calculation in Matlab.
  • Another suggests reading the documentation, specifically the getting started guide, for guidance on performing calculations.
  • A participant shares their code but expresses difficulty in achieving the desired results.
  • Another participant proposes an alternative code snippet and notes inconsistency with results obtained from Mathcad.
  • One participant critiques Mathcad, stating it is unreliable and claims the result from Mathcad is incorrect, providing their own calculation result using a summation formula.
  • A later reply argues that the Mathcad result is correct and clarifies the use of logarithmic functions in Matlab, suggesting a modification to the code to use log10 instead of log.
  • Another participant thanks those who contributed to the discussion.
  • A new question is raised about plotting a specific equation in Matlab with defined intervals.
  • A participant provides a code snippet for plotting and comments on the cleverness of another participant's coding approach.

Areas of Agreement / Disagreement

There is disagreement regarding the correctness of the Mathcad results, with some participants asserting it is incorrect while others defend its accuracy. The discussion remains unresolved regarding the best approach to achieve the desired calculation in Matlab.

Contextual Notes

Participants express varying levels of familiarity with Matlab and Mathcad, leading to different interpretations of the results and coding practices. There are also unresolved issues regarding the efficiency and elegance of the proposed code snippets.

Who May Find This Useful

This discussion may be useful for individuals learning Matlab programming, particularly those interested in mathematical calculations and comparisons with other software tools like Mathcad.

intel2
Messages
10
Reaction score
0
how can someone do the attach calculation in Matlab?
 

Attachments

  • Picture1.png
    Picture1.png
    3 KB · Views: 720
Physics news on Phys.org
Read the documentation. The Matlab getting started guide is particularly good, and will teach you how to perform calculations like this and more.
 
i went through it but i couldn't 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
 
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
 
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

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

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:
% 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.
 
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:
Thank you to shoehorn and to Emreth ..
 
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
 

Attachments

  • untitled.JPG
    untitled.JPG
    3.6 KB · Views: 545
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:
  • #10
Tip of the Hat to Emreth ..

the way u wrote x(i) ,, is smart... once again thanks
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 32 ·
2
Replies
32
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
5
Views
3K