How can i decease one variable by 0.1; for increment of other variable by 0.5..?

2 vues (au cours des 30 derniers jours)
Darshan Joshi
Darshan Joshi le 19 Fév 2017
Commenté : Matt J le 19 Fév 2017
Say I have two variables(x&y). now for the increment of 0.5 in X; variable Y should decrease by 0.1. I have written this with IF condition. but it's lengthy. the code is as follow:
**************************************************
if temp >= 40
Iref=.9*AH;
end
if temp >= 40.5
Iref=.8*AH;
end
if temp >= 41
Iref=.8*AH;
end
if temp >= 41.5
Iref=.7*AH;
end
if temp >= 42
Iref=.6*AH;
end
if temp >= 42.5
Iref=.5*AH;
end
if temp >= 43
Iref=.4*AH;
end
if temp >= 43.5
Iref=.3*AH;
end
if temp >= 44
Iref=.2*AH;
end
if temp >= 44.5
Iref=.1*AH;
end
*******************************************************
please suggest some other short way to do this.

Réponses (1)

Matt J
Matt J le 19 Fév 2017
Modifié(e) : Matt J le 19 Fév 2017
Iref=( (-0.1/0.5)*(temp-40)+0.9) *AH;
Iref=ceil( Iref/(0.1*AH) )*0.1*AH;
  2 commentaires
Darshan Joshi
Darshan Joshi le 19 Fév 2017
it decreases constantly like a line. I want the decrement in iref after every 0.5 increment in temp. I need output like this(output of the code written in question) :
Matt J
Matt J le 19 Fév 2017
I've added a second line to discretize the output. Your plot however, does not match your code if AH is constant. Your code gives piecewise constant output whereas your plot is piecewise linear.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Numerical Integration and Differentiation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by