Mat-.C Matemaattiset ohjelmistot Luento ma 9.3.0 $z; Error, (in rtable/product) invalid arguments.z; z C z C z3 3 C z4 4 C z5 5.Tr z ; z C z C z3 3 C z4 4 C z5 5 ; Error, (in rtable/power) eponentiation operation not defined for Vectors [www.math.hut.fi/teaching/matohjelmistot/maple/harjratk.mw] /harjratk.pdf Aloitetaan Maple-opiskelu vertailemalla harj:n Maple- ja Matlab-ratkaisuja niiltä osin kuin mielekästä. Tehtävät:,3,4,5,6,3,4,5,6.. with LinearAlgebra : alias Tr = Transpose ; d Tr,, 3, 4, 5 ; y d y y y3 y4 ; z d z z z3 z4 z5 ; map t/t, ; Tr.y; # Ulkotulo := z := y := s d sum i, i =.. Dimension Tr 3 4 5 y y y3 y4 z z z3 z4 z5 3 4 5 y y y3 y4 y y y3 y4 3 y 3 y 3 y3 3 y4 4 y 4 y 4 y3 4 y4 5 y 5 y 5 y3 5 y4 ; # Aika outo virhe. Mutta klikkaa Erroria, mahtavaa! (.) (.) (.3) (.4) (.5) (.6) (.7) (.8)
Error, bad inde into Vector s d sqrt add i, i =.. Dimension ; s := C C 3 C 4 C 5 s3 d norm, ; s3 := C C 3 C 4 C 5 Dimension ; 5 3 ; 3 i; i 3. Maple Matlab (.9) (.0) (.) (.) (.3) C d,,, 3, 4 3, 6, 9 ; 3 C := 3 6 (.) C=[ 3; 3 6; 4 9]; tai C=[ones(3,) (:4)' (3:3:9)'] 4 9 C ; 6 0 4 0 35 75 4 50 08 map /, C ; 4 9 9 36 6 8 (.) (.3) C^ C.^ 4. restart; clear
y d 5$cos 3$Pi$ ; y := 5 cos 3 p plot y, =K5..5 ; 4 (3.) =linspace(-5,5); y=5*cos(3*pi*);plot(,y) f=@() 5*cos(3*pi*) f = @()5*cos(3*pi*) fplot(f,[-5,5]) shg K4 K 0 4 K K4 Tai funktiom"a"aritys: f d /5$cos 3$Pi$ ; f := /5 cos 3 p plot f, =K5..5 ; (3.) 4 K4 K 0 4 K K4 c) sin 7$ K sin 5$ y d cos 7$ C cos 5$ ; sin 7 K sin 5 y := cos 7 C cos 5 plot denom y, =K.. ; (3.3) =linspace(-,); oso=sin(7*)-sin(5*); nimi=cos(7*)+cos(5*); plot(,nimi);shg =linspace(-,,000); oso=sin(7*)-sin(5*); nimi=cos(7*)+cos(5*);
plot(,oso./nimi);shg ylim([-0 0]);grid on; shg K K 0 K plot y, =K..,K0..0 ; 0 5 K K 0 K5 K0 5. Maple h"avi"a"a t"ass"a Matlabille, onnistuuhan nuo, mutta hankalammin ja tehottomammin. Valitaan nyt se ty"okalu, Matlab, joka t"ah"an sopii. a) format compact A=:0 A = 3 4 5 6 7 8 9 0 A5 0 0 0 0 0 sum(ans) 5 find(a5) b) format compact B=[ 3;4 5 6;7 8 9] B = 3 4 5 6 7 8 9 sum(b5) B5
6 7 8 9 0 length(ans) 5 Yleisp"atevat (vekt. ja matr.) sum(sum(data5)) length(find(data5)) 0 0 0 0 0 sum(b5) sum(sum(b5)) 4 find(b5) 3 6 8 9 length(find(b5)) 4 A=:0 A = 3 4 5 6 7 8 9 0 A5 0 0 0 0 0 sum(ans) 5 find(a5) 6 7 8 9 0 length(ans) 5 6. restart; A=[4-5; ]
with LinearAlgebra : alias Lsolve = LinearSolve ; Lsolve A d 4, K5, ; 4 K5 A := b d, 9 ; b := 9 y d Lsolve A, b ; y := 4 (5.) (5.) (5.3) (5.4) b=[;9] y=a\b A=[4-5; ] b=[;9] y=a\b A = 4-5 b = 9 y = 4 Viel"a helpommin suoraan yleisellä solve:lla: restart; yhtalot d 4$ K 5$y =, $ C y = 9 ; yhtalot := C y = 9, 4 K 5 y = (5.5) ratk d solve yhtalot,, y ; ratk := = 4, y = (5.6) ; (5.7) X d subs ratk, ; X := 4 (5.8) Y d subs ratk, y ; Y := (5.9) subs ratk, yhtalot ; 9 = 9, = (5.0) Helpompi, mutta "vaarallisempi": assign ratk ; ; 4 (5.) y; (5.) subs ratk, yhtalot ; 9 = 9, = (5.3) Kas, odottelin virhett"a, mutta ei tullutkaan, voi harmi! restart; C = F*a +b
kaava d C = a$f C b; kaava := C = a F C b (5.4) yht d subs C = 0, F = 3, kaava ; yht := 0 = 3 a C b (5.5) yht d subs C =K40, F =K40, kaava ; yht := K40 = K40 a C b (5.6) ratk d solve yht, yht, a, b ; ratk := a = 5 9, b = K60 9 solve kaava, F ; Kb C C a Ffun d C/ Kb C C ; a Ffun := C/ Kb C C a assign ratk ; Ffun C ; 3 C 9 5 C (5.7) (5.8) (5.9) (5.0) h d 5; h := 5 (5.) pisteet d seq K50 C k$h, Ffun K50 C k$h, k = 0..0 ; pisteet := K50, K58, K45, K49, (5.) K40, K40, K35, K3, K30, K, K5, K3, K0, K4, K5, 5, K0, 4, K5, 3, 0, 3 matri pisteet ; (5.3) C = F*a+b A=[F ; F ] B=[C;C] Nyt Matlabiin: F=3;C=0; F=-40;C=-40; A=[F ; F ] B=[C;C] format rat ab=a\b a=ab();b=ab(); <<<<<<<<<<<<<<<<<<<<<<<<<<<< F = C K b a C=(-50:5:0)'; F=(C-b)/a; [C F] Matlab-ajo komentoikkunassa: F=3;C=0; F=-40;C=-40; A=[F ; F ] B=[C;C] format rat ab=a\b a=ab();b=ab(); A = 3-40 B = 0-40 ab = 5/9-60/9 C=(-50:5:0)'; F=(C-b)/a; [C F] -50-58 -45-49 -40-40 -35-3
K50 K58 K45 K49 K40 K40 K35 K3 K30 K K5 K3 K0 K4 K5 5 K0 4 K5 3 0 3 plot pisteet ; K50 K40 K30 K0 30 0 0 K0 K0 K30 K40 K50 (5.3) -30 - -5-3 -0-4 -5 5-0 4-5 3 0 3 5 4 0 50 5 59 0 68 Voit kokeilla my"os # Matri(pisteet); Hiiren oikealla - browse. N"atti taulukko, jonka saa eportilla suoraan Ecel:ksi. 3. K"asitellaan lausekkeena: f d 4 K 7$ 3 C $ C 7$ K 0; f := 4 K 7 3 C C 7 K 0 (6.)
plot f, =K..5, y =K5..0 ; 0 y 0 K K 0 3 4 5 K0 factor f ; 4 K 7 3 C C 7 K 0 juuret d fsolve f = 0, ; juuret := K0.9474645, 0.840756773, 3.85864689, 3.80876 subs = juuret, f ; 0. seq subs = juuret i, f, i =..4 ; 0., 0., K8. 0-8, 3. 0-8 Digits; 0 Digits d 0; Digits := 0 Digits d 0; Digits := 0 df d diff f, ; df := 4 3 K C C 7 plot df, =K..5 ; (6.) (6.3) (6.4) (6.5) (6.6) (6.7) (6.8) (6.9)
50 K K 0 3 4 5 K50 K00 K50 dnollak d fsolve df = 0, ; dnollak := K0.53749459,.99535447, 3.5743799 subs = dnollak, f ; K0.9494539 subs = dnollak, f ; 8.0353856 subs = dnollak 3, f ; K0.8788980 plot f, df, =K..4 ; (6.0) (6.) (6.) (6.3) 50 K K 0 3 4 K50 K00 K50 4. restart : plot cos, sin, =K$Pi..$Pi, =linspace(-*pi,*pi); plot(,cos(),,sin())
color = blue, red ; 0.5 K p Kp p p K0.5 p t=linspace(0,*pi); =cos(t); y=sin(t); plot(,y) hold on t=linspace(0,*pi,0); plot(cos(t),sin(t)) ais square shg K plot cos, sin, =K$Pi..$Pi, color = blue, red ; 0.5 K p K 3 p Kp K p p p 3 p p K0.5 K
plot cos t, sin t, t =KPi..Pi ; 0.5 K K0.5 0 0.5 K0.5 with plots : compleplot ep I$t, t = 0..$Pi ; K
0.5 K K0.5 0 0.5 K0.5 K Oma linspace-funktio Mapleen: Kun tähän on Matlabissa totuttu, niin määritellään Mapleen. Käytössä on Maplen seq, jolla muodostetaan jonoja. Kas näin se käy: linspace d a, b, n / seq a C iii * bka / nk, iii = 0..n K ; linspace := a, b, n / seq a C iii b K a, iii = 0..n K n K Yhden rivin määrittelyssä ei voi sisäisiä muuttujia lokalisoida, siksi i:n sijasta iii. (Taiteen sääntöjen mukainen pitää kirjoittaa proc:ksi, laitetaan ohjelmekokoelmaamme.) linspace 0,, 5 ; 0, 4,, 3 4, t d linspace 0, $Pi, ; t := 0, 5 p, 5 p, 3 5 p, 4 5 p, p, 6 5 p, 7 5 p, 8 5 p, 9 5 p, p d cos ~ t ; y d sin~ t ; # Mato mappaa funktion, sama kuin map(cos,t) :=, cos 5 p, cos 5 p, Kcos 5 p, Kcos 5 p, K, Kcos 5 p, (7.) (7.) (7.3)
Kcos 5 p, cos 5 p, cos 5 p, y := 0, sin 5 p, sin 5 p, sin 5 p, sin 5 p, 0, Ksin 5 p, Ksin 5 p, Ksin 5 p, Ksin 5 p, 0 plot, y ; (7.4) 0.8 0.6 0.4 0. K K0.5 0 0.5 K0. K0.4 K0.6 K0.8 5. restart; g d /piecewise O 0,,! 0, 0 ; g := /piecewise 0!,,! 0, 0 (8.) plot g, =K.. ; =linspace(-,,0); nolla=zeros(size()); y=ma(,nolla); tai:
0.8 0.6 0.4 0. K K0.5 0 0.5 z=(0).* Tiedostoon ramppi.m kirjoitetaan: ------------------------------------------------ function [ y ] = ramppi( ) % Lasketaan "ramppifuktion" arvot -vektorissa. y=ma(zeros(size()),); end ------------------------------------- help ramppi Kutsuesim: =linspace(-,); plot(,ramppi());shg 6. restart; plot.5 cos,, = 0.. Pi ; =linspace(0,pi/); plot(,cos(),'r',,,'g') grid on;shg 0=0.739 0 = 0.7390 cos(0) 0.739 0.5 0 p 6 3 p 6 5 p 6 p 0 d 0.737; 0 := 0.737 cos 0 ; 0.7404880963 0 d cos 0 ; 0 := 0.7404880963 (9.) (9.) (9.3)