Can You Help Me Fix this Matlab Error in My Code?

  • Thread starter Thread starter bert2002
  • Start date Start date
  • Tags Tags
    Error Matlab
Click For Summary

Discussion Overview

The discussion revolves around a MATLAB coding error encountered by a participant while attempting to implement a formula involving various parameters related to lithosphere and crustal thickness. The focus is on syntax issues and the correct use of operators in MATLAB.

Discussion Character

  • Homework-related
  • Technical explanation

Main Points Raised

  • One participant describes their MATLAB code and the specific error message they receive, seeking help with syntax.
  • Another participant suggests replacing curly brackets {} with parentheses () due to their special meaning in MATLAB, which relates to cell arrays.
  • It is proposed that '1/B' should be changed to '1./B' to ensure element-wise division instead of matrix division.
  • A question is raised about the purpose of the dot operator (.) in MATLAB, specifically in the context of element-wise operations.
  • Further clarification is provided regarding the difference between array division and matrix division.

Areas of Agreement / Disagreement

Participants generally agree on the need to correct the syntax issues in the MATLAB code, but the discussion remains focused on clarifying the implications of these changes rather than reaching a consensus on the overall solution.

Contextual Notes

There are unresolved aspects regarding the overall structure of the code and the specific operator needed in the equation for Ys1, as well as potential dependencies on the definitions of the parameters used.

bert2002
Messages
16
Reaction score
0

Homework Statement


Hello, i have a MATLAB code that simply lists a bunch of parameters with values and an equation that relates all of them together. I am getting on error that says

Error in ==> randelltest at 17
Ys0=Yl*{(Pm-Pc)*Yc/Yl*(1-Av*Tm/2*Yc/Yl)-Av*Tm*Pm/2}*(1-1/B);

Is there a problem with this syntax somewhere ?

The Attempt at a Solution



Code in full (matlab noob)% ParametersYl=100; % initial lithosphere thickness
Yc=30; % Initial crustal thickness
Pm=3400; % mantle density
Pc=2670; % crustal density
Ps=2670; % basin material density
Av=2.4*10^-5; % volumetric coefficient of thermal expansion
Tm=1300; % mantle temperature at top of asthenosphere
B=(1:0.1:4); % stretching factor

% Equation for fault controlled subsidence

Ys0=Yl*{(Pm-Pc)*Yc/Yl*(1-Av*Tm/2*Yc/Yl)-Av*Tm*Pm/2}*(1-1/B);

Ys1=Ys0/Pm(1-Av*Tm)-Ps;

plot(B,Ys1)
 
Physics news on Phys.org
bert2002 said:
Ys0=Yl*{(Pm-Pc)*Yc/Yl*(1-Av*Tm/2*Yc/Yl)-Av*Tm*Pm/2}*(1-1/B);
The brackets {} have a special meaning related to MATLAB cells, so you should replace them with (). You should also replace '1/B' with '1./B', so you get element-wise, and not matrix, division.

bert2002 said:
Ys1=Ys0/Pm What operator goes here? (1-Av*Tm)-Ps;
 
milesyoung said:
The brackets {} have a special meaning related to MATLAB cells, so you should replace them with (). You should also replace '1/B' with '1./B', so you get element-wise, and not matrix, division.

Thanks for clearing that up, what is the purpose of the "." ? I cleared up the other error you pointed out too.
 

Similar threads

  • · Replies 7 ·
Replies
7
Views
16K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 2 ·
Replies
2
Views
11K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 15 ·
Replies
15
Views
6K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 3 ·
Replies
3
Views
3K
Replies
5
Views
8K
  • · Replies 5 ·
Replies
5
Views
2K