MATLAB: Making a non linear graf


hey I have no idea on how to make a graf of a diminishing value for an equation i made.
It's just to represent the degradation of a battery that has a loss of 2.3% per year like this:
100(1-0.023) I've tried the for funktion but Don't think i enter correct values
would appriciate the help

Best Answer

  • Try this:
    initialAmount = 100;
    amountLeft = initialAmount;
    maxNumberOfYears = 50;
    for k = 2 : maxNumberOfYears
    amountLeft(k) = amountLeft(k - 1) * (1-0.023);
    fprintf('After %d years, the amount left = %.2f\n', amountLeft(k));
    plot(amountLeft, 'b.-', 'LineWidth', 2, 'MarkerSize', 20);
    grid on;
    xlabel('Time (Beginning of Year)', 'FontSize', 20);
    ylabel('Amount Left', 'FontSize', 20);
    g = gcf;
    g.WindowState = 'maximized';