~ubuntu-branches/ubuntu/natty/mathomatic/natty

« back to all changes in this revision

Viewing changes to integrate.c

  • Committer: Bazaar Package Importer
  • Author(s): Sandro Tosi
  • Date: 2010-05-27 23:29:55 UTC
  • mfrom: (1.1.26 upstream) (3.1.15 sid)
  • Revision ID: james.westby@ubuntu.com-20100527232955-xzvvnwdzy8c9mdji
Tags: 15.1.1-1
* New upstream release
* debian/patches/10_fix_makefile.dpatch
  - updated to new upstream code
* debian/patches/30_bts-459093_ftbfs_make_test_time.dpatch
  - updated to new upstream code

Show diffs side-by-side

added added

removed removed

Lines of Context:
244
244
char    *cp;
245
245
{
246
246
        int             i, j;
 
247
        int             len;
247
248
        long            v = 0;
248
249
        token_type      *source, *dest;
249
250
        int             n1, n2, *nps, *np;
250
 
        int             definite_flag = false, constant_flag = false;
251
 
        double          d1, integrate_order = 1.0;
 
251
        int             definite_flag = false, constant_flag = false, solved;
 
252
        double          integrate_order = 1.0;
252
253
        char            var_name_buf[MAX_VAR_LEN];
 
254
        long            l1;
253
255
 
254
256
        if (current_not_defined()) {
255
257
                return false;
256
258
        }
 
259
        solved = solved_equation(cur_equation);
257
260
        i = next_espace();
258
261
        for (;; cp = skip_param(cp)) {
259
262
                if (strcmp_tospace(cp, "definite") == 0) {
310
313
                        printf(_("Integrating with respect to (%s)"), var_str);
311
314
                }
312
315
                if (integrate_order != 1.0) {
313
 
                        printf(_(" %.0f times"), integrate_order);
 
316
                        printf(_(" %.*g times"), precision, integrate_order);
314
317
                }
315
318
                printf(_(" and simplifying...\n"));
316
319
        }
321
324
        factorv(source, nps, v);
322
325
        blt(dest, source, *nps * sizeof(token_type));
323
326
        n1 = *nps;
324
 
        for (d1 = 0; d1 < integrate_order; d1++) {
 
327
        for (l1 = 0; l1 < integrate_order; l1++) {
325
328
                if (!int_dispatch(dest, &n1, v, integrate_sub)) {
326
329
                        error(_("Integration failed, not a polynomial."));
327
330
                        return false;
381
384
                n1 += n2;
382
385
        }
383
386
        simpa_side(dest, &n1, false, false);
 
387
        *np = n1;
384
388
        if (n_rhs[cur_equation]) {
385
389
                blt(lhs[i], lhs[cur_equation], n_lhs[cur_equation] * sizeof(token_type));
386
390
                n_lhs[i] = n_lhs[cur_equation];
 
391
                if (solved && isvarchar('\'')) {
 
392
                        len = list_var(lhs[i][0].token.variable, 0);
 
393
                        for (l1 = 0; l1 < integrate_order && len > 0 && var_str[len-1] == '\''; l1++) {
 
394
                                var_str[--len] = '\0';
 
395
                        }
 
396
                        parse_var(&lhs[i][0].token.variable, var_str);
 
397
                }
387
398
        }
388
 
        *np = n1;
389
399
        cur_equation = i;
390
400
        return return_result(cur_equation);
391
401
}
629
639
{
630
640
        long            v = 0;
631
641
        int             i, j, k, i1, i2;
 
642
        int             len;
632
643
        int             level;
633
644
        int             iterations = 1000;      /* must be even */
634
645
        int             first_size = 0;
635
 
        int             trap_flag, singularity;
 
646
        int             trap_flag, singularity, solved;
636
647
        token_type      *ep, *source, *dest;
637
648
        int             n1, *nps, *np;
638
649
 
639
650
        if (current_not_defined()) {
640
651
                return false;
641
652
        }
 
653
        solved = solved_equation(cur_equation);
642
654
        i = next_espace();
643
655
        if (n_rhs[cur_equation]) {
644
656
                source = rhs[cur_equation];
706
718
                error_huge();
707
719
        }
708
720
#if     !SILENT
709
 
        printf(_("Approximating the definite integral\n"));
 
721
        if (n_rhs[cur_equation]) {
 
722
                printf(_("Approximating the definite integral of the RHS\n"));
 
723
        } else {
 
724
                printf(_("Approximating the definite integral\n"));
 
725
        }
710
726
        if (trap_flag) {
711
727
                printf(_("using the trapezoid method (%d partitions)...\n"), iterations);
712
728
        } else {
881
897
#if     !SILENT
882
898
        printf(_("Numerical integration successful:\n"));
883
899
#endif
 
900
        *np = n1;
884
901
        if (n_rhs[cur_equation]) {
885
902
                blt(lhs[i], lhs[cur_equation], n_lhs[cur_equation] * sizeof(token_type));
886
903
                n_lhs[i] = n_lhs[cur_equation];
 
904
                if (solved && isvarchar('\'')) {
 
905
                        len = list_var(lhs[i][0].token.variable, 0);
 
906
                        if (len > 0 && var_str[len-1] == '\'') {
 
907
                                var_str[--len] = '\0';
 
908
                        }
 
909
                        parse_var(&lhs[i][0].token.variable, var_str);
 
910
                }
887
911
        }
888
 
        *np = n1;
889
912
        cur_equation = i;
890
913
        return return_result(cur_equation);
891
914
}