Doing Attached Calculation in Matlab

In summary, to plot the attach equation between [-4,4] with a 0.001 interval using Matlab, you would first need to create three vectors representing the values -4, -x, and 4, and then use the plot function to plot these vectors.
  • #1
intel2
10
0
how can someone do the attach calculation in Matlab?
 

Attachments

  • Picture1.png
    Picture1.png
    3 KB · Views: 643
Physics news on Phys.org
  • #2
Read the documentation. The Matlab getting started guide is particularly good, and will teach you how to perform calculations like this and more.
 
  • #3
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
 
  • #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
 
  • #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:
% 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.
 
  • #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:
  • #7
Thank you to shoehorn and to Emreth ..
 
  • #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
 

Attachments

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

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

1. How do I perform attached calculation in Matlab?

To perform attached calculation in Matlab, you can use the "attach" function. This function allows you to attach a variable or a set of variables to the current workspace, making them available for use in calculations.

2. What are the advantages of using attached calculation in Matlab?

Attached calculation in Matlab can save time and make your code more organized. By attaching variables, you don't have to constantly refer to them using their full names, which can be especially helpful when working with long variable names. It also allows you to easily switch between multiple sets of variables without having to redefine them each time.

3. Can I attach multiple variables at once in Matlab?

Yes, you can attach multiple variables at once in Matlab by using the syntax "attach(var1, var2, var3, ...)" or by using a cell array of variables as the input for the "attach" function. This can be useful when you have a large number of variables to attach.

4. How do I detach a variable in Matlab?

To detach a variable in Matlab, you can use the "detach" function. This will remove the variable from the current workspace, making it inaccessible for further calculations. Alternatively, you can also use the "clear" function to remove all attached variables at once.

5. Can I reattach a variable in Matlab after detaching it?

Yes, you can reattach a variable in Matlab after detaching it by using the "attach" function again. However, it is important to note that when you reattach a variable, it will overwrite any existing variable with the same name in the current workspace, so make sure to use unique variable names to avoid any conflicts.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
827
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
712
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
32
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
819
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
Back
Top