%Numeri complessi z1 = 3 + 4i; % Definizione con 'i' z2 = 5 - 2j; % Definizione con 'j' z3 = z1 + z2; z4 = z1 - z2; z5 = z1 * z2; z6 = z1 / z2; mod_z1 = abs(z1); % Modulo di z1 conj_z1 = conj(z1); figure; plot(real(z1), imag(z1), 'ro', 'MarkerSize', 10); % Punto rosso per z1 hold on; plot(real(z2), imag(z2), 'bx', 'MarkerSize', 10); % Punto blu per z2 grid on; xlabel('Re(z)'); ylabel('Im(z)'); title('Numeri complessi nel piano'); legend('z1', 'z2'); % Polynomial fit % Dati di esempio x = 1:10; y = [2.1, 2.9, 4.0, 5.2, 6.1, 6.8, 7.5, 9.1, 10.1, 11.2]; % Fit lineare coeff = polyfit(x, y, 1); % Adattamento lineare (grado 1) y_fit = polyval(coeff, x); % Visualizzazione plot(x, y, 'o', 'DisplayName', 'Dati'); hold on; plot(x, y_fit, '-r', 'DisplayName', 'Fit Lineare'); legend show; grid on; xlabel('x'); ylabel('y'); title('Adattamento Lineare'); % Dati di esempio x = 1:10; y = [2.1, 2.5, 3.9, 6.0, 9.1, 12.9, 17.1, 21.5, 25.8, 30.2]; % Fit polinomiale di grado 2 coeff = polyfit(x, y, 2); y_fit = polyval(coeff, x); % Visualizzazione plot(x, y, 'o', 'DisplayName', 'Dati'); hold on; plot(x, y_fit, '-r', 'DisplayName', 'Fit Polinomiale (Grado 2)'); legend show; grid on; xlabel('x'); ylabel('y'); title('Adattamento Polinomiale'); % Dati di esempio x = (0:0.1:2*pi)'; y = sin(x) + 0.1*randn(size(x)); % Dati rumorosi % Creazione del fit f = fit(x, y, 'sin1'); % Adattamento a una funzione sinusoidale % Visualizzazione plot(f, x, y); grid on; xlabel('x'); ylabel('y'); title('Adattamento con il Toolbox Curve Fitting'); %Fit a Polynomial Surface % Example data [x, y] = meshgrid(-5:0.5:5, -5:0.5:5); % Independent variables z = x.^2 + y.^2 + 2*x.*y + rand(size(x)); % Dependent variable with some noise % Reshape data for fit (fit requires column vectors) x = x(:); y = y(:); z = z(:); % Fit a second-degree polynomial surface fitted_model = fit([x, y], z, 'poly22'); % Display the model coefficients disp(fitted_model); % Plot the fit plot(fitted_model, [x, y], z); xlabel('X'); ylabel('Y'); zlabel('Z'); title('Polynomial Surface Fit'); grid on; %Fits curves of degrees 1-3 to temperature data and plots in a subplot x = 2:6; y = [65, 67, 72, 71, 63]; morex = linspace(min (x) , max (x) ); for pd= 1:3 coefs = polyfit(x,y,pd); curve = polyval(coefs,morex); subplot (1,3,pd) plot (x, y, 'ro', morex, curve) xlabel('Time') ylabel('Temperatures') title(sprintf('Degree %d' ,pd)) axis([1 7 60 75]) end %Leggere file data = readtable('data1.txt'); d = readtable('data1.txt'); x = d.x; y = d.y; plot(x,y,'o') coefs = polyfit(x,y,1); y_fit = polyval(coefs,x); plot(x,y,'o') hold on; plot(x,y_fit,'-r')