Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wolfram mathematica 如何编写程序?_Wolfram Mathematica_Procedural Programming - Fatal编程技术网

Wolfram mathematica 如何编写程序?

Wolfram mathematica 如何编写程序?,wolfram-mathematica,procedural-programming,Wolfram Mathematica,Procedural Programming,你好!!请帮我用我的程序代码做一个程序。 我有代码,包括两部分,它们是图形[…],它用矩形图绘制函数。 但是代码似乎太多了,所以我必须用一个函数的参数编写一个过程,然后当我调用它时,这个过程会用矩形函数做同样的绘图。能告诉我如何使用spx1,spx2 这是全部代码: (*Sin[x]*) data1 = Table[{x, Sin[x]}, {x, -1, 6, 0.1}]; data11 = data1[[;; , 2]];(*отримуємо набір ордин

你好!!请帮我用我的程序代码做一个程序。 我有代码,包括两部分,它们是图形[…],它用矩形图绘制函数。 但是代码似乎太多了,所以我必须用一个函数的参数编写一个过程,然后当我调用它时,这个过程会用矩形函数做同样的绘图。能告诉我如何使用spx1,spx2

这是全部代码:

        (*Sin[x]*)
data1 = Table[{x, Sin[x]}, {x, -1, 6, 0.1}];
    data11 = data1[[;; , 2]];(*отримуємо набір ординат*)localmins1 = 
     Pick[data1, MinDetect[data11, 10^-6], 1];
    localmaxs1 = Pick[data1, MaxDetect[data11, 10^-6], 1];
    Graphics[{Thick, Blue, Line[data1], Red, PointSize[0.01], 
       Point[localmins1], Point[localmaxs1]}, Axes -> True];       

spx1 = {-1, -0.35, 0.3, 0.95, 1.6, 2.375, 3.15, 3.925, 4.7, 6};
    Graphics[{Thick, Blue, Line[data1], Red, PointSize[0.01], 
      Point[localmins1], Point[localmaxs1], 
      Point[{{-1, 0}, {1.6, 0}, {-0.35, 0}, {0.3, 0}, {0.95, 0}}], Green, 
      Point[{{-0.35, -0.1342898}, {0.3, 0.29552}, {0.95, 0.813416}}], Red,
       Point[{{2.375, 0}, {3.15, 0}, {3.925, 0}, {4.7, 0}}], Green, 
      Point[{{2.375, 0.693685}, {3.15, -0.0084}, {3.925, -0.70569766}}], 
      Pink, Opacity[.7], EdgeForm[Directive[Dashed, Pink]], 
      Rectangle[{-1, -0.84147}, {-0.35, -0.342898}], 
      Rectangle[{-0.35, -0.342898}, {0.3, 0.29552}], 
      Rectangle[{0.3, 0.29552}, {0.95, 0.813416}], 
      Rectangle[{0.95, 0.813416}, {1.6`, 0.9995736030415051`}], 
      Rectangle[{1.6, 0.99957}, {2.375, 0.693685}], 
      Rectangle[{2.375, 0.693685}, {3.15, -0.0084}], 
      Rectangle[{3.15, -0.0084}, {3.925, -0.70569766}], 
      Rectangle[{3.925, -0.70569766}, {4.7, -0.9999}],}, Axes -> True]

    (*Cos[x]*)
    data2 = Table[{x, Cos[x]}, {x, -3, 4, 0.1}]; data22 = 
     data2[[;; , 2]];(*отримуємо набір ординат*)localmins2 = 
     Pick[data2, MinDetect[data22, 10^-6], 1];
    localmaxs2 = Pick[data2, MaxDetect[data22, 10^-6], 1];
    Graphics[{Thick, Blue, Line[data2], Red, PointSize[0.01], 
       Point[localmins2], Point[localmaxs2]}, Axes -> True];

    spx2 = {-3,-2.25, -1.5, -0.75,0, 0.75, 1.5, 2.25, 3};
    spxrozb11 = {-3, -2.25, -1.5, -0.75, 0};
    spxrozb22 = {0, 0.75, 1.5, 2.25, 3};
    Graphics[{Thick, Blue, Line[data2], Red, PointSize[0.01], 
      Point[localmins2], Point[localmaxs2], 
      Point[{{-2.25, 0}, {-1.5, 0}, {-0.75, 0}, {0, 0}}], Green, 
      Point[{{-2.25, -0.628}, {-1.5, 0.07}, {-0.75, 0.73}}], Red, 
      Point[{{0.75, 0}, {1.5, 0}, {2.25, 0}, {3, 0}}], Green, 
      Point[{{0.75, 0.7316}, {1.5, 0.07}, {2.25, -0.628}}], Pink, 
      Opacity[.7], EdgeForm[Directive[Dashed, Pink]], 
      Rectangle[{-3, -0.989992}, {-2.25, -0.628}], 
      Rectangle[{-2.25, -0.628}, {-1.5, 0.07}], 
      Rectangle[{-1.5, 0.07}, {-0.75, 0.7316}], 
      Rectangle[{-0.75, 0.7316}, {1.6653345369377348`*^-16, 1.`}], 
      Rectangle[{1.6653345369377348`*^-16, 1.`}, {0.75, 0.7316}], 
      Rectangle[{0.75, 0.7316}, {1.5, 0.07}], 
      Rectangle[{1.5, 0.07}, {2.25, -0.628}], 
      Rectangle[{2.25, -0.628}, {3.1000000000000005`, \
    -0.9991351502732795`}]}, Axes -> True]
我试着编写过程的第一步,但即使它不起作用

f1 = Table[{x, Sin[x]}, {x, -1, 6, 0.1}];
f2 = Table[{x, Cos[x]}, {x, -3, 4, 0.1}];
data = {f1, f2};
spx1 = {-1, -0.35, 0.3, 0.95, 1.6, 2.375, 3.15, 3.925, 4.7, 6};
graph[i_] := 
 Graphics[For[i = 0, i < 3, 
   i++, {Thick, Blue, Line[data[[i]]], Red, Point[{spx1[[i]], 0}]}]]
graph[1]

******如何正确地在过程中编写?******

在上面的代码中,您能否仅根据数据1和数据2重写正反两部分中的所有点和矩形?或者所有这些点和矩形编号都必须为每个部分手动输入?还有,图形[…];不显示任何内容,因为该行末尾有分号。这是一个错误,还是因为你从你真正的问题中大大简化了它?在最后一部分中,你试图使用函数参数i作为循环迭代器。在本例中,i被赋予一个固定值1,因此不能在循环内更改。我甚至想不出你想告诉你如何解决这个问题