Array indices must be positive integers or logical values
Ältere Kommentare anzeigen
Hey guys,
I'm trying to complete a homeowrk problem and I keep running into the error "Array indices must be positive integers or logical values." I don't know what I am doing wrong since my professor told us how to do most of the problem. Any help would be greatly appreciated. Thank you!
clear;clc
x = [0.888: 0.01: 1.178]; %x values
for n = 1: 1: length(x)
%must have different vector because variable index must be an integer
f(x) = -5*x(n)^3+17*x(n)^2+8*x(n)+9; %first function
g(x) = -13*x(n)^3+16*x(n)^2+9*x(n)+18; %secon function
if f(x) == g(x)
%if the two functions outputs equal each other then they intersect
disp(x)
%displays the x value of the intersection
end
end
figure(1)
plot(x, f(x), x, g(x))
%creates a plot with two lines on the y-axis
title('WA06B by Tiffany Tabor')
xlabel('x values')
ylabel('f(x) and g(x)')
Akzeptierte Antwort
Weitere Antworten (2)
Star Strider
am 3 Okt. 2020
0 Stimmen
You will need to understand those in order to complete this.
Image Analyst
am 3 Okt. 2020
0 Stimmen
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!