Utilising matlab plots to find constants

3 views (last 30 days)
Madlab
Madlab on 8 Oct 2018
Commented: Jan on 8 Oct 2018
Finding m and c for an equation y = mx + c, with the help of math and plots.
In this case, y is data_model_1, x is time
Avoid other matlab functions like fitlm as it defeats the purpose.
I am having trouble finding the constants m and c. I am trying to find both m and c by limiting them to a range (Based on smart guess) and I need to deduce the m and c values based on the mean error range. The point where mean error range is closest to 0 should be my m and c values.
load(file)
figure
plot(time,data_model_1,'bo')
hold on
for a = 0.11:0.01:0.13
c = -13:0.1:-10
data_a = a * time + c ;
plot(time,data_a,'r');
end
figure
hold on
for a = 0.11:0.01:0.13
c = -13:0.1:-10
data_a = a * time + c ;
mean_range = mean(abs(data_a - data_model_1));
plot(a,mean_range,'b.')
end
EDIT: I have attached an example with the file "fil"
  3 Comments
Madlab
Madlab on 8 Oct 2018
Edited: Madlab on 8 Oct 2018
How to find the constants m and c with the help of plots?
I know there are other methods but I need to use mathematics and plots to solve for m and c, nothing else. There is no polyfit function anywhere in my code either.
Jan
Jan on 8 Oct 2018
While there is no polyfit in your code, it is easy to determine the constants m and c using maths instead of plots.
Again: What is the problem with the code you have posted?

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!