Math & ScienceCode for simple Equation fails

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Rahul
Posts: 29
Joined: Wed Jul 24, 2013 10:07 am

Code for simple Equation fails

Post by Rahul »

Code not working.

Sample:

Code: Select all

R' =$\frac{$\displaystyle\sum\limits_{i=1}^n(s*a_i+b_i)^2$}{2}
Error:

Code: Select all

! Missing \endgroup inserted.
<inserted text> 
                \endgroup 
l.162 ...sum\limits_{i=1}^n (s * ai + o-bi)^2$}{2}
                                                  \\
Please give suggestions.
Last edited by localghost on Wed Jul 24, 2013 5:48 pm, edited 3 times in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Code for simple Equation fails

Post by localghost »

It would be very kind if you put a little bit more effort in your problem description. That means that full sentences are better than just writing some keywords. Otherwise you create the expression that your question is not important. This applies also to the formatting of your posts especially regarding code.

Furthermore we prefer an adequate problem description in form of a self-contained and minimal example even if the problem is less complex as in this case.

The correct syntax reads like this. In-line math mode looks quite odd here.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}

\begin{document}
  $R'=\frac{\displaystyle\sum\limits_{i=1}^n(s*a_i+b_i)^2}{2}$
\end{document}
I recommend to do some basic reading.


Best regards and welcome to the board
Thorsten
Rahul
Posts: 29
Joined: Wed Jul 24, 2013 10:07 am

Code for simple Equation fails

Post by Rahul »

"If I will keep writing problem statements then how it would be cured" by saying this what is wrong in keeping the code simple and compact.
Your code is not working.

Code: Select all

\documentclass[12pt,journal,compsoc]{IEEEtran}
\usepackage{alltt}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{array}
These are the packages I am using. Ieeetran class is obtained from ieee templates.

My problem is ::

Code: Select all

\begin{document}
s= $\frac{$[n\displaystyle\sum\limits_{i=1}^n a_i * b_i -\displaystyle\sum\limits_{i=1}^n a_i \displaystyle\sum\limits_{i=1}^n b_i$]}{2}$
\end{document}
I see some problem in frac whensoever I try to introduce in it creates problem. But in the case of using it simply like

Code: Select all

s=$\frac{2}{4}$ 
it works.

Now how can this be resolved ???
Last edited by cgnieder on Wed Jul 24, 2013 1:04 pm, edited 1 time in total.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Code for simple Equation fails

Post by Johannes_B »

Code: Select all

\documentclass[12pt,journal,compsoc]{IEEEtran}
\usepackage{alltt}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{array}
\begin{document}
$R'=\frac{\displaystyle\sum\limits_{i=1}^n(s*a_i+b_i)^2}{2}$
\end{document}
Thorstens code works very well, even with IEEE. Take a look at his provided links.
I see some problem in frac whensoever I try to introduce in it creates problem.
Can you please rephrase that?
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Code for simple Equation fails

Post by cgnieder »

Rahul wrote:But in the case of using it simply like

Code: Select all

s=$\frac{2}{4}$ 
it works.
This works although it is wrong. It should be

Code: Select all

$s=\frac{2}{4}$ 
However, what you're doing in the other equation is basically this:

Code: Select all

s=$\frac{$2$}{4}$ 
which does not work! It escapes math mode inside a mathematical formula which has to fail. If you remove those unnecessary $ in your code it will compile.

You should use display mode for an equation that large, anyway:

Code: Select all

\documentclass[12pt,journal,compsoc]{IEEEtran}
\usepackage{alltt}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{array}
\begin{document}

\[
  s =
  \frac
    {
      \left[
        n\sum_{i=1}^n a_i \cdot b_i
        -\sum_{i=1}^n a_i \sum_{i=1}^n b_i
      \right]
    }
    {2}
\]

\end{document}
I recommend reading mathmode

Regards
site moderator & package author
Rahul
Posts: 29
Joined: Wed Jul 24, 2013 10:07 am

Code for simple Equation fails

Post by Rahul »

@cgnieder

The code worked. And it worked perfectly. The modifications required I will do them. I am new to LaTeX. That's y I am facing so many troubles. And I am new to the posts too. I wish to understand the significance of \[ before s and at the last, in this code.

Code: Select all

\[
  s =
  \frac
    {
      \left[
        n\sum_{i=1}^n a_i \cdot b_i
        -\sum_{i=1}^n a_i \sum_{i=1}^n b_i
      \right]
    }
    {2}
\]
Last edited by cgnieder on Wed Jul 24, 2013 1:36 pm, edited 1 time in total.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Code for simple Equation fails

Post by cgnieder »

Rahul wrote:I wish to understand the significance of \[
This switches to display math mode. Since you have loaded mathtools which loads amsmath internally

Code: Select all

\[ <formula> \]
is equivalent to

Code: Select all

\begin{equation*}
 <formula>
\end{equation*}
You should really get yourself some introductory text on LaTeX as this belongs to the very basics. Thorsten already provided you with a link that points to helpful resources.

Regards
site moderator & package author
Rahul
Posts: 29
Joined: Wed Jul 24, 2013 10:07 am

Re: Code for simple Equation fails

Post by Rahul »

I think the codes are more about alignment. When I align the code it runs otherwise show error. And can you tell what is display mode.

I am really thankful to you both but now my document is on the verge of finish. I cannot afford time to read the doc.That's why I came here.And I found it really helpful.It is people like you that make the world beautiful.

Thanks a lot and yes you will be seeing my problems in the forum quite often till my doc is not finished.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Code for simple Equation fails

Post by cgnieder »

Rahul wrote:I cannot afford time to read the doc.
That's a pity since those documents are really helpful and help you to understand the basics of how LaTeX works. Every one of us reads documents, manuals and what-nots if we don't know how to proceed. Only if that doesn't help we ask questions.

Code: Select all

\documentclass{article}
\begin{document}
Some text with inline math $a+b=c$ and maybe text after it. Now follows a displayed equation:
\begin{equation}
  a + b = c
\end{equation}
This equation is now followed by text \emph{within the same paragraph}.
\end{document}
If you compile the code above (e.g. by clicking on the OPEN IN WRITELATEX link you will see what the difference between inline and displayed math is.

Regards
site moderator & package author
Rahul
Posts: 29
Joined: Wed Jul 24, 2013 10:07 am

Re: Code for simple Equation fails

Post by Rahul »

Please don't be hazy about it. If we don't ask from you then what is the basic need of these forums. The only way to I can interact is this forum.I looked over the links you send me but when I downloaded one of them then most of the files were in .tex format.

Reading more to know more :))
Thanks for the link.
Post Reply