years = [1800, 1810, 1820, 1830, 1840, 1850, 1860, 1870, 1880, 1890,1900, 1910, 1920, 1930, 1940, 1950, 1960, 1970, 1980, 1990,2000, 2010, 2020]; population = [5.3, 7.2, 9.6, 12.9, 17.1, 23.2, 31.4, 38.6, 50.2, 62.9,76.0, 92.0, 106.5, 123.2, 131.7, 150.7, 179.3, 204.0,226.5, 251.4, 281.4, 309.3, 329.4]; t = years - 1800; logistic_model = @(params, t) params(1) ./ (1 + (params(1) - params(2)) ./ params(2) .* exp(-params(3) * t)); initial_guess = [400, 5.3, 0.03]; params = lsqcurvefit(logistic_model, initial_guess, t, population); K = params(1); N0 = params(2); r = params(3); t_2030 = 2030 - 1800; population_2030 = logistic_model(params, t_2030); fprintf('2030年预测人口: %.2f 百万\n', population_2030); fprintf('拟合参数: 承载能力 K = %.2f, 初始人口 N0 = %.2f, 增长率 r = %.4f\n', K, N0, r); figure; plot(years, population, 'bo', 'DisplayName', '实际数据'); hold on; plot(years, logistic_model(params, t), 'r-', 'DisplayName', 'Logistic模型'); xlabel('年份'); ylabel('人口 (百万)'); title('美国人口数据与Logistic模型拟合'); legend; grid on;
标签:%.,马上,years,params,logistic,2030,population From: https://www.cnblogs.com/AkaashiKeiji/p/18539855