• Non ci sono risultati.

ˆ Solution for Ex 0. Write the following function. 1

N/A
N/A
Protected

Academic year: 2021

Condividi "ˆ Solution for Ex 0. Write the following function. 1"

Copied!
3
0
0

Testo completo

(1)

ˆ Solution for Ex 0. Write the following function.

1 function [x,iter] = NewtonMod(f,fp,x0,tol,maxiter,m) 2 %NEWTON for finding multiple zeros of functions 3 res = tol+1; iter = 0; % Initialize

4 while res > tol && iter < maxiter 5 x0 = x0m*f(x0)/fp(x0);

6 res = abs(f(x0)); iter = iter+1;

7 end 8 x = x0;

9 if iter >= maxiter

10 disp('no convergence iter > maxiter') 11 end

1

(2)

ˆ Solution for Ex 1. Write the following function.

1 function [x,iter] = fixedpoint(g,x0,tol,maxiter)

2 %FIXEDPOINT for finding fixedpoints of the function g 3 res = tol+1; iter = 0; % Initialize

4 while res > tol && iter < maxiter

5 x1 = g(x0);

6 res = abs(x1x0); x0 = x1; iter = iter+1;

7 end 8 x = x1;

9 if iter >= maxiter

10 disp('no convergence iter > maxiter') 11 end

2

(3)

ˆ Solution for Ex 2. On the script called Esercizio2 write 1 close all

2 clear all 3 clc

4 f = @(x) x.^2log(x.^2 + 2);

5 x = linspace(2,2);

6 figure 7 hold on

8 plot(x,f(x)), grid;

9 %% g = +() sqrt(log(x.^2 + 2))

10 gp = @(x) x./sqrt(log(x.^2+2))./(x.^2+2);

11 figure 12 hold on

13 plot(x,gp(x)), grid;

14 %%

15 g = @(x) sqrt(log(x.^2 + 2)); format long 16 x1=fixedpoint(g,2,1.e06,50)

17 x2=fzero(f,2) 18 %%

19 g = @(x)sqrt(log(x.^2 + 2)); format long 20 x1=fixedpoint(g,2,1.e06,50)

21 x2=fzero(f,2)

-2 -1.5 -1 -0.5 0 0.5 1 1.5 2

-1 -0.5 0 0.5 1 1.5 2 2.5

-2 -1.5 -1 -0.5 0 0.5 1 1.5 2

-0.4 -0.3 -0.2 -0.1 0 0.1 0.2 0.3 0.4

3

Riferimenti

Documenti correlati

The mathematical representations characterized by the smallest number of nonzero parameters are called canonical forms.. • The most interesting canonical forms are

[r]

Lo si denoti

NOTE: In the solution of a given exercise you must (briefly) explain the line of your argument and show the main points of your calculations1. Solutions without adequate

Indeed we know that the maximal eigenvalue is the max- imum value taken by the quadratic form on the unit sphere (that is, the set of all

[r]

In practice we need to compare the number of iterations needed by each algorithm to reach the solution up to the desired tolerance... First verify (on paper) that the xed point

[r]