How to iterate and plot in matlab

Hello! I need some help with Matlab.
I would like to solve and plot the following function:
I've called dxa/dW 'y', and I know everything except for xa, which I'd like to iterate from 0 to 1 in steps of 0.05. This is what I have written, but I am obviously doing something wrong because it gives me an error.
I would really apreciate it if you could help because I need it as soon as possible for my thesis.
Thank you in advance.

 Accepted Answer

Floris
Floris on 10 Jun 2019
Edited: Floris on 10 Jun 2019
Hello,
Maybe I misunderstand what you are attempting to do, so please let me know if you need any additional clarification. I notice you are varying x from 0 to 1, however, you do not seem to have the variable W in the equation where you define y. In order to plot W, you will need to map W using linspace() as well as X. Checkout the link below for help on what I think you are trying to do:
So I have the following code below:
x = linspace(0,1,200);
kw = 91371;
Ca0 = 1.81 * 10 ^ -4;
Fa0 = 0.1233;
K = 2;
y = (1/Fa0) * ((kw .* Ca0 .* (1 - x)) ./ (1 + K .* Ca0 .* (1 - x)))
plot(x, y);

6 Comments

You don't have to put "." (point) everywhere. Just when you do some operations between vectors:
y = 1/Fa0*kw*Ca0*(1 - x) ./ (1+K*Ca0*(1 - x));
Thank you all so much. That really helped. I have one last question.
I've separated the variables so now the equation looks like this:
Captura.PNG
I've plotted it in Excel and the graph it gives me is correct because I know it should have that shape:
Captura.PNG
But I can't write it properly on Matlab. Now that I know it is correct, I need some help with the Matlab code. This is what I've written:
x = linspace(0,1,200); % conversion
%CONSTANTS
kw = 91371; % [1/(s*g)]
Ca0 = 1.81*10^-4; % [mol/l]
Fa0 = 0.1233; %[kg/s]
K = 1.29; %[l/mol]
%EVOLUTION OF THE CONVERSION 'x' AS A FUNCTION OF THE MASS CATALYST 'W'
W = x.*Fa0.*(1+K.*Ca0.*(1 - x)) ./ kw.*Ca0.*(1 - x);
plot (x,W);
Thank you again.
You forgot parentheses at the end:
W = x.*Fa0.*(1+K.*Ca0.*(1 - x)) ./ kw.*Ca0.*(1 - x);
Don't know if your expression for W is correct
Marina Gonzalez
Marina Gonzalez on 15 Jun 2019
Edited: Marina Gonzalez on 15 Jun 2019
How would I write it on Matlab to solve the expression you wrote and plot x vs W? Take into account that x should be values between 0 and 1.
read about int

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Asked:

on 10 Jun 2019

Commented:

on 15 Jun 2019

Community Treasure Hunt

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

Start Hunting!